Last active
August 29, 2015 14:09
-
-
Save mikz/df306f511d40017c5375 to your computer and use it in GitHub Desktop.
Messed up handling of keyword arguments splat in ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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
Nice trap. You should probably stick to using
options = {}
here, which surely follows better the principle of least surprise.