Methods such as abc? return true/false Hashie::Extensions::MethodReader.

This commit is contained in:
Zloy 2015-01-14 06:56:43 -05:00 committed by dB
parent eeba6ee3af
commit c2225e0d26
4 changed files with 37 additions and 0 deletions

View File

@ -9,6 +9,7 @@
* [#260](https://github.com/intridia/hashie/pull/260): Added block support to Extensions::DeepMerge - [@galathius](https://github.com/galathius).
* [#254](https://github.com/intridea/hashie/pull/254): Added public utility methods for stringify and symbolize keys - [@maxlinc](https://github.com/maxlinc).
* [#261](https://github.com/intridea/hashie/pull/261): Fixed bug where Dash.property modifies argument object - [@d_tw](https://github.com/d_tw).
* [#264](https://github.com/intridea/hashie/pull/264): Methods such as abc? return true/false with Hashie::Extensions::MethodReader - [@Zloy](https://github.com/Zloy).
* Your contribution here.
## 3.3.2 (11/26/2014)

View File

@ -1,6 +1,30 @@
Upgrading Hashie
================
### Upgrading to 3.2.2
#### Testing if key defined
In versions <= 3.2.1 Hash object being questioned doesn't return a boolean value as it's mentioned in README.md
```ruby
class MyHash < Hash
include Hashie::Extensions::MethodAccess
end
h = MyHash.new
h.abc = 'def'
h.abc # => 'def'
h.abc? # => 'def'
```
In versions >= 3.2.2 it returns a boolean value
```ruby
h.abc? # => true
h.abb? # => false
```
### Upgrading to 3.2.1
#### Possible coercion changes

View File

@ -35,6 +35,10 @@ module Hashie
def method_missing(name, *args)
return self[name.to_s] if key?(name.to_s)
return self[name.to_sym] if key?(name.to_sym)
if name[-1] == '?'
kname = name.to_s[0..-2]
return key?(kname) || key?(kname.to_sym)
end
super
end
end

View File

@ -29,6 +29,14 @@ describe Hashie::Extensions::MethodReader do
expect { subject.new.awesome }.to raise_error(NoMethodError)
end
it 'returns false for undefined keys if key with question has been called ' do
expect(subject.new.awesome?).to eq false
end
it 'returns true for defined keys if key with question has been called' do
expect(subject.new(awesome: 'sauce').awesome?).to eq true
end
describe '#respond_to?' do
it 'is true for string keys' do
expect(subject.new('awesome' => 'sauce')).to be_respond_to(:awesome)