Re:Why I Like Ruby
by erikpukinskis on Friday July 16, 2010 @02:47AM
(#1520494)
I should say the first example I gave is from DHH's awesome presentation on his favorite Rails 3 features: http://www.youtube.com/watch?v=b0iKYRKtAsA
In many other languages, you could set up an API like this, but instead of taking a block, the "resources" function would have to accept some sort of nested data structure. That gets you pretty far, but what about when you want to do something that the parser of that data structure didn't expect? Usually you can't.
But in Ruby, code is data and you can do whatever you want in those blocks. You could do this, for example:
That would map /people/george/eat_apple, /people/george/eat_orange, and /people/george/eat_peach.And maybe that's not that impressive to you, but you can inject arbitrary code in there. That's what people mean when they talk about expressiveness.
Examples of this are everywhere in the Ruby world. Check out HAML and assert_select.
APIs + Rigid data structures = Pain and suffering
APIs + Ruby blocks = Flexibility and power