Skip to content

Instantly share code, notes, and snippets.

@dlt
Created December 23, 2011 20:07
Show Gist options
  • Save dlt/1515236 to your computer and use it in GitHub Desktop.
Save dlt/1515236 to your computer and use it in GitHub Desktop.
whyyyyyyy?
class Hash
def [](k)
fetch(k) do
super[k.intern] || super[k.to_s]
end
end
end
{ key: 'EXPECTED'}['key']
NoMethodError: super: no superclass method `[]' for {:key=>"EXPECTED"}:Hash
from /home/dlt/projects/programming/ruby/webapi/hash.rb:2:in `block in []'
from /home/dlt/projects/programming/ruby/webapi/hash.rb:2:in `fetch'
from /home/dlt/projects/programming/ruby/webapi/hash.rb:2:in `[]'
from /home/dlt/projects/programming/ruby/webapi/hash.rb:4:in `<top (required)>'
from (irb):1:in `load'
from (irb):1
from /home/dlt/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment