Skip to content

Instantly share code, notes, and snippets.

@tallakt
Created April 7, 2011 07:02
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tallakt/907190 to your computer and use it in GitHub Desktop.
Save tallakt/907190 to your computer and use it in GitHub Desktop.
#old style
a={}
a[:test] = {}
a[:test][:second_test] = 'Hello hash!'
# new style
# emulates working with directories
b = {}
b/:test = {}
b/:test/:second_test = 'Hello hash!'
# other examples
b = [4 => 'goodbye', 5 => 'hello'}
puts b/5
c = [1, 2, 3, 4, 5]
puts c/3
# extension to Hash class
class Hash
def /(index)
self[index]
end
# this will not work unfortunately
def /=(index, value)
self[index] = value
end
end
@dexterous
Copy link

Hey @kaiwren, maybe https://github.com/c42/wrest could use this for composing large URIs from a base URI.

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