Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit ab5c534c516ab7dadf71e592db2e095adb191153 1 parent 98c21c7
@saimonmoore saimonmoore authored
Showing with 16 additions and 17 deletions.
  1. +16 −17 lib/choices/rails.rb
View
33 lib/choices/rails.rb
@@ -24,6 +24,22 @@ 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
@@ -31,22 +47,5 @@ def from_file(name)
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
Please sign in to comment.
Something went wrong with that request. Please try again.