

Elements of Ruby Style - qhoxie
http://www.pathf.com/blogs/2008/10/elements-of-ruby-style/

======
mhartl
This list is crap. He advocates the ridiculous

    
    
        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.

~~~
Freaky
_all_users.select( &:is_active).map(&:name).sort_

 _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'

~~~
mhartl
_It's standard in 1.9_

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.

------
randrews
It is so sad that this is still what people worry about for code style.
Anything here could be done in an automatic code formatter written in a
weekend.

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?

------
thwarted
Advocates readability in one instance, then says to use fewer spaces for
indentation? The only reason to use indention less than 4 spaces (some would
say even 4 is too few) is so you can cram more nested statements in, and if
you're running out of room nesting such that a smaller indentation would help,
your problem is not related to indentation.

------
qqq
Why break lines at a fixed length yourself instead of letting your editor's
wordwrap handle it?

~~~
mileszs
The wrapped line (2nd line, if you will) is not indented. I find a word-
wrapped line of code more difficult to read than a manually broken and
indented line of code.

