Alternative Block Syntaxes
Get to know some alternative syntaxes that we use for blocks in Ruby.
Next to the syntax shown before, using do
and end
, Ruby comes with an
alternative syntax, which uses curly braces for defining a block.
These two statements do exactly the same:
Press + to interact
5.times doputs "Oh, hello!"end5.times { puts "hello!" }
Both statements define a ...
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy