From 3aa73ad7ffd02399c52cd40e5406676f93832004 Mon Sep 17 00:00:00 2001 From: Jaime Iniesta Date: Tue, 2 Mar 2010 22:25:07 +0100 Subject: [PATCH] Added respond_to? to ActiveSupport::StringInquirer to match method_missing implementation (responds to method names ending with '?') --- .../lib/active_support/string_inquirer.rb | 4 ++++ activesupport/test/string_inquirer_test.rb | 8 ++++++++ 2 files changed, 12 insertions(+), 0 deletions(-) diff --git a/activesupport/lib/active_support/string_inquirer.rb b/activesupport/lib/active_support/string_inquirer.rb index e6b1f39..d256479 100644 --- a/activesupport/lib/active_support/string_inquirer.rb +++ b/activesupport/lib/active_support/string_inquirer.rb @@ -17,5 +17,9 @@ module ActiveSupport super end end + + def respond_to?(method_name, include_private = false) + super || method_name.to_s[-1,1] == "?" + end end end diff --git a/activesupport/test/string_inquirer_test.rb b/activesupport/test/string_inquirer_test.rb index 7f11f66..fc947e5 100644 --- a/activesupport/test/string_inquirer_test.rb +++ b/activesupport/test/string_inquirer_test.rb @@ -12,4 +12,12 @@ class StringInquirerTest < Test::Unit::TestCase def test_missing_question_mark assert_raise(NoMethodError) { ActiveSupport::StringInquirer.new("production").production } end + + def test_respond_to_match + assert ActiveSupport::StringInquirer.new.respond_to?(:production?) + end + + def test_respond_to_miss + assert !ActiveSupport::StringInquirer.new.respond_to?(:production) + end end -- 1.6.6.1