Skip to content

Instantly share code, notes, and snippets.

@puneetpandey
Last active October 6, 2015 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save puneetpandey/8e11a24406bf4d6792a5 to your computer and use it in GitHub Desktop.
Save puneetpandey/8e11a24406bf4d6792a5 to your computer and use it in GitHub Desktop.
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