Hacker News new | past | comments | ask | show | jobs | submit login

"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...


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: