Skip to content

Instantly share code, notes, and snippets.

@fbernier
Last active December 27, 2015 00:19
Show Gist options
  • Save fbernier/7237370 to your computer and use it in GitHub Desktop.
Save fbernier/7237370 to your computer and use it in GitHub Desktop.
a ranged hash implementation in ruby
class RangedHash
def initialize(hash={})
@ranged_hash = hash
end
def []=(key, value)
@ranged_hash[key] = value
end
def [](key)
(@ranged_hash.detect{ |range, value| range.cover?(key) } || []).last
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment