Ruby Help
Posted: Tue Mar 28, 2017 9:18 pm
Hi all
Needing some help if one of you Ruby experts could assist.
I have a hash that I need to change:

I've been Googling this for two days now to no avail, so I thought I'd ask here
In order to get the result I want I have to call a definition and change it, surely it must be possible to get the result in one definition... its self explanatory if you care to have a look:
Hope someone can help
PS sorry for the blurred pic . . . Had to resize it
Needing some help if one of you Ruby experts could assist.
I have a hash that I need to change:

I've been Googling this for two days now to no avail, so I thought I'd ask here
In order to get the result I want I have to call a definition and change it, surely it must be possible to get the result in one definition... its self explanatory if you care to have a look:
Code: Select all
@my_hash = { 0 =>"Piano", 1 =>"Guitar", 5 =>"Flute" }
def my_1st_attempt
(0..6).map {|n| a = @my_hash.fetch(n,"- - -");Hash[n,a]}
end
def result_that_i_want
my_1st_attempt.reduce Hash.new, :merge
end
watch "my_1st_attempt", my_1st_attempt
watch "result_that_i_want", result_that_i_want
Hope someone can help
PS sorry for the blurred pic . . . Had to resize it
