Skip to content

Instantly share code, notes, and snippets.

@stujo
Created February 1, 2014 19:46
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 stujo/8757665 to your computer and use it in GitHub Desktop.
Save stujo/8757665 to your computer and use it in GitHub Desktop.
#Using Symbols as keys
customer = {
name: "Billy Bob",
tel: "(415)555-5555",
}
customer['name']
customer.keys.each do |key| puts key.object_id end
customer.delete_if {| key, value | :tel == key }
hsh.compare_by_identity Use object ids instead of equality for lookups
hsh.default Returns the default value that would be used
hsh.default= Sets the default value
hsh.default_proc Returns the proc to be executed on failing lookup
hsh.default_proc= Assigns a default proc
hsh.default_proc= proc do |hash,key| "default for #{key}" end
delete(key) {| key | block } → value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment