-
-
Save chad/1490380 to your computer and use it in GitHub Desktop.
simple dictionary without using arrays or hashes
This file contains hidden or 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
def add(key, value, dictionary = Proc.new{}) | |
lambda do |x| | |
key == x ? value : dictionary.call(x) | |
end | |
end | |
d = add("a",5) | |
d = add("b",6, d) | |
p d.call("b") | |
p d.call("a") | |
p d.call("c") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Proc.new is less picky about arity than lambda