diff options
Diffstat (limited to 'railties/guides/source/active_support_core_extensions.textile')
-rw-r--r-- | railties/guides/source/active_support_core_extensions.textile | 22 |
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 |