Elements of Ruby Style
pathf.com
pathf.com
x = if boolean then 3 else 5 end
in place of x = boolean ? 3 : 5
Then we have return if x = null
which assigns the value of "null" to x (if null exists). Maybe he meant return if x == nil
If so, this is better rendered as return if x.nil?
Finally, all_users.select(&:is_active).map(&:name).sort
isn't standard Ruby; it will (currently) only work in Rails.isn't standard Ruby; it will (currently) only work in Rails.
It's standard in 1.9, and making it work in 1.8 is all of 3 lines:
class Symbol
def to_proc() proc {|obj, *args| obj.__send__(self, *args) } end
end
Or if you've got facets: require 'facets/symbol/to_proc'That's why I said "(currently)". From the official Ruby homepage: The current stable version is 1.8.7.
making it work in 1.8 is all of 3 lines
I agree, but this still makes it not standard Ruby. The article should have mentioned this.
Why not an article on, say, Ruby API design? Use blocks, overload these (but not these) operators, DSLs, etc?
You know, elements of style that matter?