?

Log in

No account? Create an account

What I do like about ruby

« previous entry | next entry »
May. 13th, 2006 | 03:26 pm
music: Daft Punk - Discovery - Veridis Quo

Completely object oriented + functional = crazy weird calls on the return value of iterators. I fear it's utterly illegible though.
  def has_category?(category)
    not categories.select do |cat| 
      cat.cat_name == category
    end.empty?
  end
It would look totally normal in lisp though (pseudocode)
(define (has-category? category categories)
	(not (empty? (filter (lambda (cat)
			             (equal? cat category))
		              categories))))
Although the ruby version would be faster to just return true when the comparison equals true:
  def has_category?(category)
   categories.each do |cat| 
      return true if cat.cat_name == category
    end
    return false
  end
Faster and more legible, but not very functional. Bah.

| Leave a comment | Share

Comments {0}