aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/module/delegation.rb
diff options
context:
space:
mode:
authorLi Ellis Gallardo <lellisga@gmail.com>2013-04-25 17:00:13 -0500
committerLi Ellis Gallardo <lellisga@gmail.com>2013-04-25 21:36:22 -0500
commitccbe02343934956d3bb11c7167e0493f9d8f08fd (patch)
treeeaa4b31acfb5a306fdb1c5c680fec17f6a56078d /activesupport/lib/active_support/core_ext/module/delegation.rb
parentfaa2c71deef44ded8ef73513e63229d057552540 (diff)
downloadrails-ccbe02343934956d3bb11c7167e0493f9d8f08fd.tar.gz
rails-ccbe02343934956d3bb11c7167e0493f9d8f08fd.tar.bz2
rails-ccbe02343934956d3bb11c7167e0493f9d8f08fd.zip
Delegation method bug
Add documentation and test to delegation method that make sure we're aware that when a delegated object is not nil or false and doesn't respond to the method it will still raise a NoMethodError exception.
Diffstat (limited to 'activesupport/lib/active_support/core_ext/module/delegation.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/module/delegation.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb
index e608eeaf42..c0828343d8 100644
--- a/activesupport/lib/active_support/core_ext/module/delegation.rb
+++ b/activesupport/lib/active_support/core_ext/module/delegation.rb
@@ -112,6 +112,20 @@ class Module
# end
#
# Foo.new.zoo # returns nil
+ #
+ # If the delegate object is not +nil+ or +false+ and the object doesn't
+ # respond to the delegated method it will raise an exception.
+ #
+ # class Foo
+ # def initialize(bar)
+ # @bar = bar
+ # end
+ #
+ # delegate :name, to: :@bar
+ # end
+ #
+ # Foo.new("Bar").name # raises NoMethodError: undefined method `name'
+ #
def delegate(*methods)
options = methods.pop
unless options.is_a?(Hash) && to = options[:to]