Because a regular expression can have different behaviors depending on
(e.g. behavior of \w) I decided that all my code should specify the
explicitly (e.g. /\w+/n instead /\w+/). So I tried to set up some hooks
monitor the creation of each Regexp and raise an exception if the kcode
missing. Like this:
alias old_initialize initialize
raise “NO KCODE!” if kcode.nil?
And it works fine if I use Regexp.new, but in the majority of cases the
is expressed as a literal and the initialize is NOT EXECUTED.
RuntimeError: NO KCODE!
So I tried an alternate approach and set the hook into the =~ operator,
problem; the method override is completely ignored:
class String; def =~(o); raise “S”; end; end
class Regexp; def =~(o); raise “R”; end; end
“bar” =~ /bar/ #=> 0
/foo/ =~ “foo” #=> 0
So… anyone has any idea how I can tackle that problem?