Reputation: 118
I'd like to know how get the specified field from Hash.
{"codeid"=>120023, "eppocode"=>"1BOBO", "prefname"=>"Pikant", "level"=>7}
I have this Hash and i want to get level
field (7) becouse i need to compare it afterwards
Thanks!
Upvotes: 0
Views: 54
Reputation: 84443
You can use either Hash#[] or Hash#dig for this. There are other ways to do this too such as pattern matching, but those are overkill for what you're doing.
For example:
h = {
"codeid" => 120023,
"eppocode" => "1BOBO",
"prefname" => "Pikant",
"level" => 7,
}
h["level"]
#=> 7
h.dig "level"
#=> 7
Upvotes: 1
Reputation: 107107
Like this:
hash = {"codeid"=>120023, "eppocode"=>"1BOBO", "prefname"=>"Pikant", "level"=>7}
hash["level"]
#=> 7
Upvotes: 0