Something like that would be a reasonable thing to do:
class Foo
def initialize(t) @text = t
end
def =~(x) @text =~ x
end
end
And it works for non-capturing regexps,
but when we want to capture something
$1 etc. are bound only within the =~ method,
and when the method returns they are
restored to their previous values.
Foo.new(“Hello”) =~ /(e)/ # => 1
$1 # => nil
Is it possible to somehow get =~ like that work,
even if it takes heavy metaprogramming hackery ?
On Tue, Aug 08, 2006 at 02:51:37PM +0900, Tomasz W. wrote:
but when we want to capture something
$1 etc. are bound only within the =~ method,
and when the method returns they are
restored to their previous values.
Foo.new(“Hello”) =~ /(e)/ # => 1
$1 # => nil
Is it possible to somehow get =~ like that work,
even if it takes heavy metaprogramming hackery ?
[ruby-talk:202600]
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.