Answers for "ruby loop dictionary"

1

iterating over hash, ruby

# iterating_over_hashes.rb

person = {name: 'bob', height: '6 ft', weight: '160 lbs', hair: 'brown'}

person.each do |key, value|
  puts "Bob's #{key} is #{value}"
end


#Returns
#Bob's name is bob
#Bob's height is 6 ft
#Bob's weight is 160 lbs
#Bob's hair is brown
Posted by: Guest on December-31-2020
0

iterate over each key value in hash ruby

restaurant_menu = { "Ramen" => 3, "Dal Makhani" => 4, "Coffee" => 2 }
restaurant_menu.each do | item, price |
  puts "#{item}: $#{price}"
end
Posted by: Guest on January-21-2021
0

iterate through values of an object rails

@work_profile.attributes.each do |attr_name, attr_value|
  ...
end
Posted by: Guest on March-05-2020

Browse Popular Code Answers by Language