Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifies respond_to? according to method_missing #40

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/hashie/mash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ def shallow_update(other_hash)
# Will return true if the Mash has had a key
# set in addition to normal respond_to? functionality.
def respond_to?(method_name, include_private=false)
return true if key?(method_name)
super
return super || true
end

def method_missing(method_name, *args, &blk)
Expand Down
8 changes: 6 additions & 2 deletions spec/hashie/mash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@
it 'should delete with String key' do
subject.delete('details')
subject.details.should be_nil
subject.should_not be_respond_to :details
subject.key?(:details).should be_false
end

it 'should delete with Symbol key' do
subject.delete(:details)
subject.details.should be_nil
subject.should_not be_respond_to :details
subject.key?(:details).should be_false
end
end
end
Expand Down Expand Up @@ -225,6 +225,10 @@ class SubMash < Hashie::Mash
it 'should respond to a set key' do
Hashie::Mash.new(:abc => 'def').should be_respond_to(:abc)
end

it 'should respond to a non set key' do
Hashie::Mash.new.should be_respond_to(:abc)
end
end

context "#initialize" do
Expand Down