From: Michael Linfield Date: 2008-04-04T12:41:33+09:00 Subject: Re: using a range as a key Alex Wayne wrote: > class RangedHash > def initialize(hash) > @ranges = hash > end > > def [](key) > @ranges.each do |range, value| > return value if range.include?(key) > end > nil > end > end > > ranges = RangedHash.new( > 1..10 => 'low', > 21..30 => 'medium', > 41..50 => 'high' > ) > ranges[5] #=> "low" > ranges[15] #=> nil > ranges[25] #=> "medium" Beautiful. Works great, However! The file that I'll be importing will probably contain a large amount of traffic being pushed at RangedHash.new If I had a predefined data file ie: 12345..12350 => 89734, 23456..23460 => 23532 ect ect. commas separating the ranges like above...How do I import the literal of that file instead of the string. file = File.readlines('testdata.txt') # this creates only 1 array element file[0].class #=> String file[1] #=> nil So this obviously wouldn't work in a manner of the following: ranges = RangedHash.new(file) Same goes for file = File.open('testdata.txt', 'w+') Maybe Marshaldump is the way to go? Ideas? Thanks! - Mac -- Posted via http://www.ruby-forum.com/.