On Fri, Jun 8, 2012 at 12:20 PM, Iñaki Baz Castillo <[email protected]> wrote:
> 2012/6/8 Jan E. <[email protected]>:
>> "Iñaki Baz Castillo" <[email protected]> wrote in post #1063634:
>>> 2012/6/7 cyber c. <[email protected]>:
>>> Regexp.new(/^([a-zA-Z]+)(.+)$/).match(str).captures
>>
>> Why are you using Regexp.new, when /^([a-zA-Z]+)(.+)$/ already *is* a
>> Regexp? This seems nonsensical to me, like String.new("abc").
>
> Yes, I'm used to store my regexps in some module/class constants and
> usually use Regexp.new for some reason I don't remember right now,
> maybe because it allows passing a string which is useful in certain
> cases:
>
> Regexp.new("^([a-zA-Z]+)(.+)$")
Like
irb(main):001:0> s = "foo"
=> "foo"
irb(main):002:0> rx = /^([a-zA-Z]+)#{s}(.+)$/
=> /^([a-zA-Z]+)foo(.+)$/
irb(main):003:0> puts rx
(?-mix:^([a-zA-Z]+)foo(.+)$)
=> nil
?
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
-- You received this message because you are subscribed to the Google Groups
ruby-talk-google group. To post to this group, send email to
[email protected]. To unsubscribe from this group, send email
to [email protected]. For more options, visit this
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en