Permalink
Browse files

Delegate to choices for boolean methods even if they're not defined

  • Loading branch information...
1 parent 98c21c7 commit ab5c534c516ab7dadf71e592db2e095adb191153 @saimonmoore saimonmoore committed Dec 20, 2010
Showing with 16 additions and 17 deletions.
  1. +16 −17 lib/choices/rails.rb
View
@@ -24,29 +24,28 @@ def from_file(name)
self.send("#{key}=", value)
end
end
+
+ def respond_to?(method)
+ super or method.to_s =~ /=$/ or (method.to_s =~ /\?$/ and @choices.key?($`))
+ end
+
+ private
+
+ def method_missing(method, *args, &block)
+ if method.to_s =~ /=$/ or method.to_s =~ /\?$/
+ @choices.send(method, *args)
+ elsif @choices.key?(method)
+ @choices[method]
+ else
+ super
+ end
+ end
end
if defined? Rails::Application::Configuration
Rails::Application::Configuration.send(:include, Choices::Rails)
elsif defined? Rails::Configuration
Rails::Configuration.class_eval do
include Choices::Rails
- include Module.new {
- def respond_to?(method)
- super or method.to_s =~ /=$/ or (method.to_s =~ /\?$/ and @choices.key?($`))
- end
-
- private
-
- def method_missing(method, *args, &block)
- if method.to_s =~ /=$/ or (method.to_s =~ /\?$/ and @choices.key?($`))
- @choices.send(method, *args)
- elsif @choices.key?(method)
- @choices[method]
- else
- super
- end
- end
- }
end
end

0 comments on commit ab5c534

Please sign in to comment.