4 ms·
In Ruby: employees.find_all &:isPartTime
by erikpukinskis 16y ago
In Ruby:
employees.find_all &:isPartTime
- patio11 16y agoAnd I liked employees.select {|employee| employee.part_time?} Crikey, should buy a book...
- Confusion 16y agoPersonally, I prefer your version; the &: version starts reeking of Perl line noise. Although I believe Ruby would benefit from an _ for not explicitly named block arguments.
- mark_l_watson 16y agoI agree, I also prefer the slightly longer version. OK, enough small talk ... :-)
- steveklabnik 16y agoAs a random note for anyone who's wondering how this syntax came about, this is the Symbol#to_proc [1] method, which was actually a monkeypatch from Rails that ended up making its way back into Ruby proper. 1: http://ruby-doc.org/core-1.9/classes/Symbol.html#M000031 http://ruby-doc.org/core-1.9/classes/Symbol.html#M000031
- jarin 16y agoThank goodness Symbol#to_proc was introduced in Ruby 1.9, the Rails implementation of it was slow as hell: http://www.lukeredpath.co.uk/blog/optimising-symbol-to_proc.html http://www.lukeredpath.co.uk/blog/optimising-symbol-to_proc....
- wuputah 16y agoThat was fixed some time ago. It is very marginally slower to use Symbol#to_proc now (a constant time difference to actually create the Proc), but not enough to warrant a change in practical use.