Method with Block at Invocation

Local variable passed to a method as an argument is pretty straightforward: we pass the variable and it is either used or not inside the method.

Block at invocation is a bit different: every method can use a block as an argument but in order to be executed, the method needs to be constructed with yield.

def some_method
  puts 'un mouton !'

some_method do
  puts 'Dessine-moi...'

# => Dessine-moi...
#    un mouton !
Links to this page