Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaks Hash#dig #3

Open
al opened this issue May 31, 2018 · 0 comments
Open

Breaks Hash#dig #3

al opened this issue May 31, 2018 · 0 comments

Comments

@al
Copy link

al commented May 31, 2018

The extension of Hash#dig isn't compatible with the core method and can cause some horrible stuff to happen. E.g.

>> g = { foo: [10, 11, 12] }
=> {:foo=>[10, 11, 12]}
>> g.dig(:foo, 1)
=> 11
>> class Hash
>>   def dig(*path)
>>     path.inject(self) do |location, key|
?>       location.respond_to?(:keys) ? location[key] : nil
>>     end
>>   end
>> end
=> :dig
>> g = { foo: [10, 11, 12] }
=> {:foo=>[10, 11, 12]}
>> g.dig(:foo, 1)
=> nil
>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant