aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-08-15 16:26:37 +0100
committerJon Leighton <j@jonathanleighton.com>2011-08-15 16:26:37 +0100
commitc80876f77880a97f94d2255ff9405bb080a6faa4 (patch)
treeffcba03b1c3a88c8498f8fbe830dd9464be7d68a /railties
parent2e2f3f5a469cb441e52fb161647ea5fd27d98d81 (diff)
downloadrails-c80876f77880a97f94d2255ff9405bb080a6faa4.tar.gz
rails-c80876f77880a97f94d2255ff9405bb080a6faa4.tar.bz2
rails-c80876f77880a97f94d2255ff9405bb080a6faa4.zip
Document Object#public_send
Diffstat (limited to 'railties')
-rw-r--r--railties/guides/source/active_support_core_extensions.textile24
1 files changed, 24 insertions, 0 deletions
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.
+
+<ruby>
+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
+</ruby>
+
+NOTE: Defined in +active_support/core_ext/object/public_send.rb+.
+
h3. Extensions to +Module+
h4. +alias_method_chain+