A hash with support for grouping keys and values.
gem install range-hash
require 'range-hash'
Setting and getting key/value pairs:
hash = RangeHash.new
hash[4..8] = 'hello'
hash[12..20] = 'world'
hash[4] # => 'hello'
hash[6] # => 'hello'
hash[14] # => 'world'
hash[20] # => 'world'
RangeHash
supports all the Enumerable
methods like each
and map
:
hash.each do |index, value|
# yields each index (4, 5, 6, 7, 8, etc) along with
# the corresponding value
end
No external requirements.
bundle exec rake
should do the trick. Alternatively you can run bundle exec rspec
, which does the same thing.
- Cameron C. Dutro: http://github.com/camertron