Ruby Quicktips
rubyquicktips.tumblr.com
rubyquicktips.tumblr.com
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 :(
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.
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