4 ms·
Ruby can use both "{...}" and "do ... end", with a slight difference between the two (precedence): def some_method { ... } def some_method do ... end
by clyfe 16y ago
Ruby can use both "{...}" and "do ... end", with a slight difference between the two (precedence):
def some_method { ... }
def some_method do ... end
- djacobs 16y agoI don't believe the second one works. Usually you'd define a method using: def some_method # do something end Usually you'll only use do after a method that's already defined, in order to pass a block of code to it.
- steveklabnik 16y agoYou are correct: ruby-1.9.2-p0 > def something; "hey" end => nil ruby-1.9.2-p0 > something => "hey" Adding the do makes it not work. def doesn't have a do.