Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class MyLittleProgram
def execute
h = { h1: 'value1', h2: 'value2', h3: 'value3', h4: 'value4' }
a = [ '1', '2', '3', '4' ]
h.each_with_index do |(k, v), i|
break if a.size > h.keys.size
a.each_with_index { |val, index|
if i == index
h[k] = v.to_s + '_' + val.to_s
end
}
end
end
end
e = MyLittleProgram.new
p e.execute
# Output => h = { :h1 => "value1_1", :h2 => "value2_2", :h3 => "value3_3", :h4 => "value4_4" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment