Read more

Default block arguments for Ruby 1.8.7

Henning Koch
December 29, 2010Software engineer at makandra GmbH

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
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

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
Posted by Henning Koch to makandra dev (2010-12-29 14:41)