From fc71d592195b6e04e04cdbb5e640716b0d909e91 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Strza=C5=82kowski?=
 <lukasz.strzalkowski@gmail.com>
Date: Sat, 17 Jul 2010 17:28:07 +0800
Subject: Introduced redefine_method

---
 .../source/active_support_core_extensions.textile  | 22 ++++++++++++++++++++++
 1 file changed, 22 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 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
-- 
cgit v1.2.3

