I have a coworker who is actively trying to convince me that I should not use do..end and instead use curly braces for defining multiline blocks in Ruby.
I'm firmly in the camp of only using curly braces for short one-liners and do..end for everything else. But I thought I would reach out to the greater community to get some resolution.
So which is it, and why? (Example of some shoulda code)
context do
setup { do_some_setup() }
should "do somthing" do
# some more code...
end
end
or
context {
setup { do_some_setup() }
should("do somthing") {
# some more code...
}
}
Personally, just looking at the above answers the question for me, but I wanted to open this up to the greater community.
There a few points of view on this, it's really a matter of personal preference. Many rubyists take the approach you do. However, two other styles that are common is to always use one or the other, or to use
{}
for blocks that return values, anddo ... end
for blocks that are executed for side effects.