
Ruby Quicktips - jmonegro
http://rubyquicktips.tumblr.com/
======
kbaribeau
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.

Also, doesn't exactly make you look smart :(

------
anovaskulk
Looks more like worthless Rails tips.

~~~
sunkencity
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.

~~~
jherdman
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.

~~~
sunkencity
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

