Default block arguments for Ruby 1.8.7

Posted . Visible to the public.

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
Keywords
1.8.6
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2010-12-29 13:41)