From: Maurizio De Santis Date: 2010-08-01T21:56:03+09:00 Subject: Re: what is the correct way to extend native methods? David A. Black wrote: > > It's one underlying method (C function) with two Ruby names. If you > redefine one of the Ruby names you break the binding between that name > and the underlying method, and if you add an alias then there's a third > name. Each binding is separate; they don't automatically change > together. > uhhh I think I've understood: In order to do what I want to do, I should implement something like this: class Array def slice_with_regexp(*args) return self.select{ |val| val =~ args[0] } if args.size == 1 and args[0].is_a?(Regexp) # code that executes C function called by [] and slice end alias_method :slice_with_regexp, :slice alias_method :slice_with_regexp, :[] end that is stupid 'cause breaks Array.slice performances. Right? Thanks a lot David! -- Posted via http://www.ruby-forum.com/.