I appreciate the tips, but please don't confuse ruby and rails.
I'm scared for the poor newbies who don't know where to look for help when things go wrong. If they think they have a ruby problem when it's actually a rails problem they'll be stuck looking in the wrong places for help.
Rails tips sure, but some of them were pretty interesting to me. Didn't know that irb had _ like in perl, and that error_messages_for took those nifty named parameters.
Some similar tips of my own:
Enumerable.each_with_object sort of like foldl/inject but without the explicit return of the memo is a pretty nice monkeypatch that exists in activesupport. Object.returning is pretty nice too. Creates an object to return and then yields to a block, very handy.
FYI: #returning is a hack that #tap supplants, and is supported in Ruby 1.8.7 natively, and is supported in Rails via ActiveSupport for older versions of Ruby.
Tap is also an incredibly nifty function, but they are slightly different, I hadn't thought of using tap in the same way as returning before you mentioned it.
Using returning with a local variable makes for superbly readable code imho:
def foo
returning values = [] do
values << 'bar'
values << 'baz' if @iffy
end
end
def foo
[].tap do |values|
values << 'bar'
values << 'baz' if @iffy
end
end
I'm scared for the poor newbies who don't know where to look for help when things go wrong. If they think they have a ruby problem when it's actually a rails problem they'll be stuck looking in the wrong places for help.
Also, doesn't exactly make you look smart :(