Problem: Trying to merge two Ranges into a Hash
- From: "Drew" <latortuga@xxxxxxxxx>
- Date: 13 Jun 2006 20:33:03 -0700
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 :)
.
- Follow-Ups:
- Re: Problem: Trying to merge two Ranges into a Hash
- From: Dave Burt
- Re: Problem: Trying to merge two Ranges into a Hash
- From: ekofoed
- Re: Problem: Trying to merge two Ranges into a Hash
- From: rcoder
- Re: Problem: Trying to merge two Ranges into a Hash
- From: Martin DeMello
- Re: Problem: Trying to merge two Ranges into a Hash
- From: Gordon Thiesfeld
- Re: Problem: Trying to merge two Ranges into a Hash
- Prev by Date: Ruby Calendar?
- Next by Date: NewB question on ruby data structure
- Previous by thread: Ruby Calendar?
- Next by thread: Re: Problem: Trying to merge two Ranges into a Hash
- Index(es):
Relevant Pages
|