Re:What Pythonistas Think of Ruby
by steveklabnik on Wednesday February 03, 2010 @02:50PM
(#1098650)
"get" is a function that takes a string and a block.
And the block is bound to the uri given in the string, so your guess is correct.
Ruby always confuses me with this flexible syntax...
Re:What Pythonistas Think of Ruby
by steveklabnik on Wednesday February 03, 2010 @03:11PM
(#1098715)
It's possible that you just haven't read enough ruby, then. There are only two variations on the syntax of passing a block to a function, "do/end" and "{ }". By convention, multiline blocks use do/end, and single line blocks use {}.
It's also possible that one of the things in the article is the gotcha, flexible parenthesis. By convention, Rubyists tend to use parenthesis when defining functions, but not when calling them:
def get(path, opts={}, &block)
get "/hello" do
not get("hello") do
Which would still work, if you preferred. The exception to this is chaining method calls: Users.find_all_by_age(23).select {|user| user.first_name == "steve" }
... not that that's an awesome use of ActiveRecord, but whatever.
It's unclear what "get" is. Is it a function? What does it return? My guess would be that it returns a function bound to the handler of a "/hi" url, but that's a guess.