ruby how to loop through an array
array = [1, 2, 3, 4, 5, 6]
array.each { |x| puts x }
ruby how to loop through an array
array = [1, 2, 3, 4, 5, 6]
array.each { |x| puts x }
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
ruby iterate hash with index
hash.each_with_index do |(key, value), index|
# ...
end
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us