On Wed, May 30, 2012 at 5:50 PM, Doug Jolley <[email protected]> wrote: >> By the way: In Ruby you can leave out the parentheses for method calls >> (unless there's ambiguity). So instead of >> >> puts(clubs.suit().inspect()) >> >> you can simply write >> >> puts clubs.suit.inspect
> I've been meaning to respond to this. Yes, I am aware of that fact. > Some claim that it makes the code more readable. I actually think that > it does the opposite and makes the code less readable. The reason that > I think that is that when I am reading Ruby code and I encounter an > identifier by itself, I don't really know whether that identifier is a > variable or a method. If I see an identifier followed immediately by > '()'; then, I know for sure that that identifier is a method. > Consequently, I try to remember to use explicit parenthesis. I doubt > that I do a very good job; but, that's my thinking. You need to do whatever feels best for you. I'd just add if you do not know whether something is a method or a local variable then your methods might be too long or you use too many variables. :-) Btw, in this particular case there is an even better way to rewrite the code: p clubs.suit or, if you prefer parens p clubs.suit() p(clubs.suit()) If you need to inspect more complex structures results are better when doing require 'pp' pp clubs.suit pp clubs.suit() pp(clubs.suit()) Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ -- You received this message because you are subscribed to the Google Groups ruby-talk-google group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at https://groups.google.com/d/forum/ruby-talk-google?hl=en
