summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Rodi <redjazz96@gmail.com>2014-07-06 00:35:51 -0400
committerJeremy Rodi <redjazz96@gmail.com>2014-07-06 08:23:08 -0400
commit211deb06db1884c66cf146512c190f0c8052e592 (patch)
tree5d977c6f732fbb6cf1c1b162e97b159ab9c56450
parent1b84c92eaa38dc0d074ed3097fc15bad54c916ee (diff)
downloadhashie-211deb06db1884c66cf146512c190f0c8052e592.tar.gz
Allow Ranges on Rash to match _all_ Numerics
Previously, it checked only for Integers; unfortunately, that left Floats out, so passing in a float would cause it to look it up normally. This also changes the range checking to `cover?` instead of `include?`. Also adds a line to a test to check for float availability.
-rw-r--r--CHANGELOG.md1
-rw-r--r--lib/hashie/rash.rb4
-rw-r--r--spec/hashie/rash_spec.rb6
3 files changed, 9 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9d66c74..51796c2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
## Next
* [#179](https://github.com/intridea/hashie/pull/179) Mash#values_at will convert each key before doing the lookup - [@nahiluhmot](https://github.com/nahiluhmot).
+* [#184](https://github.com/intridea/hashie/pull/184) Allow Ranges on Rash to match all Numerics - [@medcat](https://github.com/medcat)
* Your contribution here.
## 3.1 (6/25/2014)
diff --git a/lib/hashie/rash.rb b/lib/hashie/rash.rb
index 1caa4c6..d2d766a 100644
--- a/lib/hashie/rash.rb
+++ b/lib/hashie/rash.rb
@@ -89,10 +89,10 @@ module Hashie
end
end
- when Integer
+ when Numeric
# see if any of the ranges match the integer
@ranges.each do |range|
- yield @hash[range] if range.include? query
+ yield @hash[range] if range.cover? query
end
when Regexp
diff --git a/spec/hashie/rash_spec.rb b/spec/hashie/rash_spec.rb
index 68072ef..c69c7d1 100644
--- a/spec/hashie/rash_spec.rb
+++ b/spec/hashie/rash_spec.rb
@@ -37,6 +37,12 @@ describe Hashie::Rash do
expect(subject[1001]).to be_nil
end
+ it 'finds floats from ranges' do
+ expect(subject[10.1]).to eq 'rangey'
+ expect(subject[1.0]).to eq 'rangey'
+ expect(subject[1000.1]).to be_nil
+ end
+
it 'evaluates proc values' do
expect(subject['abcdef']).to eq 'bcd'
expect(subject['ffffff']).to be_nil