Skip to content

Instantly share code, notes, and snippets.

@chad
Forked from latompa/dict.rb
Created December 17, 2011 14:42
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 chad/1490380 to your computer and use it in GitHub Desktop.
Save chad/1490380 to your computer and use it in GitHub Desktop.
simple dictionary without using arrays or hashes
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")
@chad
Copy link
Author

chad commented Dec 17, 2011

Proc.new is less picky about arity than lambda

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