Skip to content

Instantly share code, notes, and snippets.

@mikz
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikz/df306f511d40017c5375 to your computer and use it in GitHub Desktop.
Save mikz/df306f511d40017c5375 to your computer and use it in GitHub Desktop.
Messed up handling of keyword arguments splat in ruby
class Result
attr_reader :object, :options
def initialize(object = nil, **options)
@object = object
@options = options
end
end
args = { value: true }
res = Result.new(args)
puts res.object.inspect
puts res.options.inspect
@unleashed
Copy link

Nice trap. You should probably stick to using options = {} here, which surely follows better the principle of least surprise.

@unleashed
Copy link

Or maybe convert object to a named parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment