Project

General

Profile

Actions

Bug #11117

closed

When you refine String with to_regexp, then it breaks Regexp.try_convert even when the refinement is not used

Added by jirutka (Jakub Jirutka) over 9 years ago. Updated over 9 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
2.2.2p95
[ruby-core:69064]

Description

I’ve run into a very strange bug with refinements. Let me show you:

module Ref
  refine String do
    def to_regexp
    end
  end
end

Regexp.try_convert('foo')
# or Regexp.union('foo', 'bar')
bug.rb:8:in `try_convert': undefined method `to_regexp' for "foo":String (NoMethodError)
	from test.rb:8:in `<main>'

Note that the refinement is not used (using), only declared, and yet it has affected behaviour of the refined class! This problem occurs only when the method is named to_string. It seems that there’s some serious scoping issue with refinements.

I’ve reproduced this issue on MRI 2.2.2p95, 2.1.5p273, and 2.0.0p598.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0