Skip to content

Instantly share code, notes, and snippets.

@dminuoso dminuoso/foo.rb
Last active Nov 6, 2017

Embed
What would you like to do?
class Hash
def self.setter(*args)
-> (paths, val, obj) {
obj.deep_dup.tap do |o|
*dir, final = paths
if dir.empty?
o.store(final, val)
else
o.dig(*dir).store(final, val)
end
end
}.curry[*args]
end
end
a = { foo: 23 }
Hash.setter [:foo], 42, a
p a #=> {:foo=>42}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.