From c80876f77880a97f94d2255ff9405bb080a6faa4 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Mon, 15 Aug 2011 16:26:37 +0100 Subject: Document Object#public_send --- .../source/active_support_core_extensions.textile | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'railties/guides/source/active_support_core_extensions.textile') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 781d3d08cd..8716e94bd9 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -452,6 +452,30 @@ Examples of +in?+: NOTE: Defined in +active_support/core_ext/object/inclusion.rb+. +h4. +public_send+ + +This method is available by default in Ruby 1.9, and is backported to Ruby 1.8 by Active Support. Like the regular +send+ method, +public_send+ allows you to call a method when the name is not known until runtime. However, if the method is not public then a +NoMethodError+ exception will be raised. + + +class Greeter + def hello(who) + "Hello " + who + end + + private + + def secret + "sauce" + end +end + +greeter = Greeter.new +greeter.public_send(:hello, 'Jim') # => "Hello Jim" +greeter.public_send(:secret) # => NoMethodError + + +NOTE: Defined in +active_support/core_ext/object/public_send.rb+. + h3. Extensions to +Module+ h4. +alias_method_chain+ -- cgit v1.2.3 From 53a13083ecc7f99ff04d3fe54f8cb1d68e486aac Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 16 Aug 2011 10:34:18 -0700 Subject: AS guide: document in Module#delegate that the method must be public in the target --- railties/guides/source/active_support_core_extensions.textile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties/guides/source/active_support_core_extensions.textile') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 8716e94bd9..38920c2edb 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -888,7 +888,9 @@ end It is shorter, and the intention more obvious. -The macro accepts several methods: +The method must be public in the target. + +The +delegate+ macro accepts several methods: delegate :name, :age, :address, :twitter, :to => :profile -- cgit v1.2.3 From 8ba491acc31bf08cf63a83ea0a3c314c52cd020f Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Thu, 25 Aug 2011 18:51:17 +0100 Subject: Revert all the stuff to do with disallowing non-public methods for Module#delegate --- .../source/active_support_core_extensions.textile | 24 ---------------------- 1 file changed, 24 deletions(-) (limited to 'railties/guides/source/active_support_core_extensions.textile') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index df863935cf..b2436a2e68 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -452,30 +452,6 @@ Examples of +in?+: NOTE: Defined in +active_support/core_ext/object/inclusion.rb+. -h4. +public_send+ - -This method is available by default in Ruby 1.9, and is backported to Ruby 1.8 by Active Support. Like the regular +send+ method, +public_send+ allows you to call a method when the name is not known until runtime. However, if the method is not public then a +NoMethodError+ exception will be raised. - - -class Greeter - def hello(who) - "Hello " + who - end - - private - - def secret - "sauce" - end -end - -greeter = Greeter.new -greeter.public_send(:hello, 'Jim') # => "Hello Jim" -greeter.public_send(:secret) # => NoMethodError - - -NOTE: Defined in +active_support/core_ext/object/public_send.rb+. - h3. Extensions to +Module+ h4. +alias_method_chain+ -- cgit v1.2.3