From 9585f795cfd512a307c0ad9371c0e25c00f2cfa2 Mon Sep 17 00:00:00 2001 From: Robert Gleeson Date: Sun, 23 Mar 2014 10:16:13 +0100 Subject: [PATCH] return Method objects for keys set and written at runtime --- lib/pry/config/behavior.rb | 2 +- spec/config_spec.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/pry/config/behavior.rb b/lib/pry/config/behavior.rb index da555920..5d2a5d35 100644 --- a/lib/pry/config/behavior.rb +++ b/lib/pry/config/behavior.rb @@ -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 diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 9a9ec561..0652619d 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -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)