Read more

Ruby: required keyword arguments in the pre-2.1 era

Daniel Straßner
October 01, 2018Software engineer at makandra GmbH

Starting with Ruby 2.0 you can define methods with keyword arguments.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

In 2.1+ required keyword arguments can be defined by using a colon without default value:

def match(value, ignore:)
  # ...
end

To accomplish something similar in ruby 1.8, use:

def match(value, options = {})
  ignore = options.fetch(:ignore)
  # ...
end
Posted by Daniel Straßner to makandra dev (2018-10-01 13:24)