[#78633] ruby/spec needs help from CRuby committers — Benoit Daloze <eregontp@...>
Currently, ruby/spec is maintained mostly by individuals and enjoys the
13 messages
2016/12/13
[#78963] Re: ruby/spec needs help from CRuby committers
— Urabe Shyouhei <shyouhei@...>
2017/01/04
I did ask attendees of last developer meeting to join this
[#78642] Re: ruby/spec needs help from CRuby committers
— Eric Wong <normalperson@...>
2016/12/14
Benoit Daloze <eregontp@gmail.com> wrote:
[ruby-core:78717] [Ruby trunk Feature#9846] Regexp#to_regexp
From:
nobu@...
Date:
2016-12-18 02:34:39 UTC
List:
ruby-core #78717
Issue #9846 has been updated by Nobuyoshi Nakada. Description updated ```ruby case when ary = Array.try_convert(o) # do something with ary when str = String.try_convert(o) # do something with str when re = Regexp.try_convert(o) # do something with re else # do other thing end ``` ---------------------------------------- Feature #9846: Regexp#to_regexp https://bugs.ruby-lang.org/issues/9846#change-62089 * Author: Wayne Conrad * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- There should be `Regexp#to_regexp`, just as there is `Array#to_ary` and `String#to_str`. ```ruby p [].to_ary # => [] p ''.to_str # => "" p //.to_regexp # undefined method `to_regexp`... ``` The use case is code like this: ```ruby if o.respond_to?(:to_ary) # do something with o.to_ary elsif o.respond_to?(:to_str) # do something with o.to_str elsif o.respond_to?(to_regexp) # can't do this today # do something with o.to_regexp ``` The workaround is to use `Regexp.try_convert`. `Regexp.try_convert` accepts either a `Regexp` or an object that responds to `#to_regexp`; so this code works fine (and is in some ways better): ```ruby elsif re = Regexp.try_convert(o) # do something with o ``` Still, that `Regexp` does not respond to `#to_regexp` surprised me. Does it surprise anyone else? ---Files-------------------------------- 0001-re.c-rb_reg_to_regexp-add-to_regexp.patch (2 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>