Bug #8205

Regexp.union behavior and Regexp.try_convert

Added by Alexander Yunin about 1 year ago. Updated 7 months ago.

Assignee:Zachary Scott
Target version:2.1.0
ruby -v:1.9.3p374 Backport:


Hi! Why Regexp.union('/../') trying to convert string with directly call rbcheckregexptype(arg) (re.c:3139) instead of rbregstryconvert (re.c:3122)? I think second variant would be more correct, and i would be able to rewrite Regexp.tryconvert in my code for changing behavior as i need.
For example: i have the code where was implemented String#toregexp which breaks default behavior of Regexp.union and i got incorrect regexp. But i can't (for some reasons) to rewrite toregexp method. Yes, stupid example, but it's real situation.

Associated revisions

Revision 43061
Added by Zachary Scott 7 months ago

  • re.c: [DOC] arguments of Regexp::union receive #to_regexp [Bug #8205]


#1 Updated by Tomoyuki Chikanaga about 1 year ago

  • Status changed from Open to Feedback


Could you show us a reproducive code or a testcase?

#2 Updated by Alexander Yunin 8 months ago


Bug description is incorrect, sorry. Now i want to say that implementation of String#to_regexp can breaks behavior of Regexp::union.

class String
def toregexp
regexp/') #=> /regexp/

And it's not documented now.

#3 Updated by Tomoyuki Chikanaga 7 months ago

  • Category set to doc
  • Status changed from Feedback to Assigned
  • Assignee set to Zachary Scott
  • Target version set to 2.1.0

Hello, avyy.

That makes sense.
I think it's spec that Regexp.union internally convert arguments with to_regexp, but it is undocumented behavior. I think it's a documentation issue.

#4 Updated by Zachary Scott 7 months ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r43061.
Alexander, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

  • re.c: [DOC] arguments of Regexp::union receive #to_regexp [Bug #8205]

Also available in: Atom PDF