How to pass a range to a hash to iterate from index 1 to the last?
h = {}
h[1..-1].each_pair do |key,value|
puts "#{key} = #{value}
end
This code returns an error. how can i go through the range in a hash ??
EDIT:
I want to print the first key and value without any calculations.
From the second key and value, I want to do some calculations on my hash.
For this, I wrote this code ... store_content_in_hash containing the key and values.
first_key_value = store_content_in_hash.shift
f.puts first_key_value[1]
f.puts
store_content_in_hash.each_pair do |key,value|
store_content_in_hash[key].sort.each {|v| f.puts v }
f.puts
end
Any better way to solve this problem?
source
share