Skip to content

Instantly share code, notes, and snippets.

@jpowers
Last active August 1, 2017 20:29
Show Gist options
  • Save jpowers/5731878 to your computer and use it in GitHub Desktop.
Save jpowers/5731878 to your computer and use it in GitHub Desktop.
Ruby Hash with range key
class RangedHash
def initialize(hash)
@ranges = hash
end
def [](key)
@ranges.each do |range, value|
return value if range.include?(key)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment