From: Maurizio De Santis Date: 2010-08-01T18:02:32+09:00 Subject: Re: what is the correct way to extend native methods? James Harrison wrote: >> return self.select{ |val| val.to_s =~ args[0] } if args.size == 1 >> and args[0].is_a?(RegExp) > > Try Regexp, not RegExp > > http://ruby-doc.org/core/classes/Regexp.html LOL that's what I obtain when I'm still not asleep at 3.00 am :P But now it's morning, and I have still a problem; please consider 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) slice_without_regexp(*args) end alias_method :slice_without_regexp, :slice alias_method :slice_without_regexp, :[] alias_method :slice, :slice_with_regexp end arr = %w[a b c ab] puts arr.slice(/a/).inspect # => ["a", "ab"] slice with Regexp works; correct puts arr.slice(1).inspect # => "b" original slice still works; correct puts arr[/a/].inspect # => stack level too deep ??? why?? -- Posted via http://www.ruby-forum.com/.