Project

General

Profile

Actions

Feature #3688

closed

redef keyword for method redefinition in Ruby 2.0

Added by sunaku (Suraj Kurapati) over 13 years ago. Updated over 11 years ago.

Status:
Rejected
Target version:
[ruby-core:31699]

Description

=begin
Hello,

I saw Matz's Euroko 2010 keynote1 where he mentioned adding the
ability to redefine methods gracefully in Ruby 2.0. I mean, more
gracefully than this:

class Hash
# save the original method
alias original_initialize initialize

 # redefine the method
 def initialize(*args, &block)
   # do something extra ...

   # call the original method
   __original_initialize__(*args, &block)

   # do something more ...
 end

end

I suggest adding a "redef" keyword to Ruby 2.0 for this purpose:

class Hash
# redefine the method
redef initialize(*args, &block)
# do something extra ...

   # call the original method
   super

   # do something more ...
 end

end

The "redef" keyword should also have a twin "redefine_method"
method for use in block-based metaprogramming:

class Hash
# redefine the method
redefine_method :initialize do |*args, &block|
# do something extra ...

   # call the original method
   super

   # do something more ...
 end

end

Thanks for your consideration.

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0