Hey, all.
Is it possible to have a string in and symbol in the same hash?
my_hash {
“one” => “1”,
two: 2
}
Thank you!
Hey, all.
Is it possible to have a string in and symbol in the same hash?
my_hash {
“one” => “1”,
two: 2
}
Thank you!
What do your tests reveal?
My question is the same…
The answer is yes. A key can be any object, and all the keys of a Hash
don’t have to be of the same type.
Hmm… let’s see shall we?
~ $ irb
irb(main):001:0> my_hash = {
irb(main):002:1* “one” => “1”,
irb(main):003:1* two: 2
irb(main):004:1> }
=> {“one”=>“1”, :two=>2}
irb(main):005:0>
Yup. We did indeed get a hash with both Strings and Symbols as keys.
Don’t you just love Ruby?
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs