return Method objects for keys set and written at runtime

This commit is contained in:
Robert Gleeson 2014-03-23 10:16:13 +01:00
parent 075b4e376c
commit 9585f795cf
2 changed files with 29 additions and 1 deletions

View File

@ -74,7 +74,7 @@ module Pry::Config::Behavior
end
alias_method :eql?, :==
def respond_to?(key, include_private=false)
def respond_to_missing?(key, include_private=false)
key?(key) or @default.respond_to?(key) or super(key, include_private)
end

View File

@ -50,6 +50,34 @@ describe Pry::Config do
end
describe "#respond_to_missing?" do
before do
@config = Pry::Config.new(nil)
end
it "returns a Method object for a dynamic key" do
@config["key"] = 1
method_obj = @config.method(:key)
method_obj.name.should == :key
method_obj.call.should == 1
end
end
describe "#respond_to?" do
before do
@config = Pry::Config.new(nil)
end
it "returns true for a local key" do
@config.zzfoo = 1
@config.respond_to?(:zzfoo).should == true
end
it "returns false for an unknown key" do
@config.respond_to?(:blahblah).should == false
end
end
describe "#default" do
it "returns nil" do
local = Pry::Config.new(nil)