Skip to content

Instantly share code, notes, and snippets.

@latompa
Created December 17, 2011 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save latompa/1488752 to your computer and use it in GitHub Desktop.
Save latompa/1488752 to your computer and use it in GitHub Desktop.
simple dictionary without using arrays or hashes
def dictionary
lambda {|x| nil }
end
def add(key, value, dictionary)
lambda do |x|
key == x ? value : dictionary.call(x)
end
end
d = dictionary
d = add("a",5, d)
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