aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorŁukasz Strzałkowski <lukasz.strzalkowski@gmail.com>2010-07-17 17:28:07 +0800
committerAaron Patterson <aaron.patterson@gmail.com>2010-07-19 23:44:46 +0800
commitfc71d592195b6e04e04cdbb5e640716b0d909e91 (patch)
tree0c14affc958db48099b87a8f987891a9b5d5a1cf /railties
parent247886e1b4256aeebc6b5fde0549400240b04e35 (diff)
downloadrails-fc71d592195b6e04e04cdbb5e640716b0d909e91.tar.gz
rails-fc71d592195b6e04e04cdbb5e640716b0d909e91.tar.bz2
rails-fc71d592195b6e04e04cdbb5e640716b0d909e91.zip
Introduced redefine_method
Diffstat (limited to 'railties')
-rw-r--r--railties/guides/source/active_support_core_extensions.textile22
1 files changed, 22 insertions, 0 deletions
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index a0ed8d6a90..a895dbded2 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -781,6 +781,28 @@ end
This may come in handy if you need to define a method that may already exist, since redefining a method issues a warning "method redefined; discarding old redefined_method_name".
+h5. +redefine_method(method_name, &block)+
+
+The method first removes method with given name (using +remove_possible_method+) and then defines new one.
+
+<ruby>
+class A; end
+
+A.class_eval do
+ redefine_method(:foobar) do |foo|
+ #do something here
+ end
+
+ #Code above does the same as this:
+
+ method_name = :foobar
+ remove_possible_method(method_name)
+ define_method(method_name) do |foo|
+ #do something here
+ end
+end
+</ruby>
+
NOTE: Defined in +active_support/core_ext/module/remove_method.rb+.
h4. Parents