D
Drew
I'm trying to take two ranges (namely, (1..26) and ('A'..'Z')) and
merge them into a new hash such that A=>1, B=>2, etc. I know I could
easily do this with a loop but I want to use an iterator and I'm not
quite sure how to approach it. I know this isn't right but it's the
best I ccould come up with:
letters = ('A'..'Z')
numbers = (1..26)
letter_to_number = {}
numbers.each, letters.each {|num, let| letter_to_number[let => num]}
If I use that, I get "1solitaire.rb:32: parse error, unexpected '\n',
expecting tCOLON2 or '[' or '.'"
(line 32 is the last line in the code above)
I'm rather new to Ruby but so far I'm very impressed with it as well as
the community - thanks for any pointers
merge them into a new hash such that A=>1, B=>2, etc. I know I could
easily do this with a loop but I want to use an iterator and I'm not
quite sure how to approach it. I know this isn't right but it's the
best I ccould come up with:
letters = ('A'..'Z')
numbers = (1..26)
letter_to_number = {}
numbers.each, letters.each {|num, let| letter_to_number[let => num]}
If I use that, I get "1solitaire.rb:32: parse error, unexpected '\n',
expecting tCOLON2 or '[' or '.'"
(line 32 is the last line in the code above)
I'm rather new to Ruby but so far I'm very impressed with it as well as
the community - thanks for any pointers