Default block arguments for Ruby 1.8.7

When your block takes an argument that should have an default, only in Ruby 1.9 you can say:

block = lambda do |message, options = {}|
  # ...
end

If you are on Ruby 1.8.6 or 1.8.7 you must resort to the following workaround:

block = lambda do |*args|
  message = args[0]
  options = args[1] || {}
end
Henning Koch Over 13 years ago