Skip to content

Instantly share code, notes, and snippets.

@AMekss
Created October 19, 2012 08:22
Show Gist options
  • Save AMekss/3916928 to your computer and use it in GitHub Desktop.
Save AMekss/3916928 to your computer and use it in GitHub Desktop.
RangedHash implementation in Ruby
class RangedHash
def initialize(hash={})
@ranged_hash = hash
end
def [](key)
(@ranged_hash.detect{|range, value| range.cover?(key) } || []).last
end
def []=(key, value)
@ranged_hash[key] = value
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment