Skip to content

Instantly share code, notes, and snippets.

@iande
Created June 5, 2011 18:37
Show Gist options
  • Save iande/1009257 to your computer and use it in GitHub Desktop.
Save iande/1009257 to your computer and use it in GitHub Desktop.
irb(main):001:0> hsh = { :a => "A", :b => "B" }
=> {:a=>"A", :b=>"B"}
irb(main):002:0> a_key = "a"
=> "a"
irb(main):003:0> a_val = "a"
=> "a"
irb(main):004:0> key = "#{a_val}.to_sym"
=> "a.to_sym"
irb(main):005:0> hsh[key]
=> nil
irb(main):006:0> hsh["#{a_val}.to_sym"]
=> nil
irb(main):007:0> hsh[a_val.to_sym]
=> "A"
irb(main):008:0> hsh[:"#{a_val}"]
=> "A"
irb(main):008:0>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment