http://ruby-doc.org/core/classes/String.html#M001849 says this:
"cat o' 9 tails" =~ '\d' #=> nil
I get this:
irb(main):001:0> "cat o' 9 tails" =~ '\d'
TypeError: type mismatch: String given
from (irb):1:in `=~'
from (irb):1
$ ruby -v
ruby 1.8.4 (2005-12-24) [i386-mswin32]
Any clues?
···
--
Alex
Alex Young wrote:
class String - RDoc Documentation says this:
"cat o' 9 tails" =~ '\d' #=> nil
I get this:
irb(main):001:0> "cat o' 9 tails" =~ '\d'
TypeError: type mismatch: String given
from (irb):1:in `=~'
from (irb):1
$ ruby -v
ruby 1.8.4 (2005-12-24) [i386-mswin32]
Any clues?
Use a regexp:
irb(main):004:0> "cat o' 9 tails" =~ /\d/
=> 7
String#=~ used to automagically convert the second arg into a regexp. It doesn't do that anymore.
···
On Jun 24, 2006, at 1:51 PM, Alex Young wrote:
class String - RDoc Documentation says this:
"cat o' 9 tails" =~ '\d' #=> nil
I get this:
irb(main):001:0> "cat o' 9 tails" =~ '\d'
TypeError: type mismatch: String given
from (irb):1:in `=~'
from (irb):1
$ ruby -v
ruby 1.8.4 (2005-12-24) [i386-mswin32]
Any clues?
-- Alex
Timothy Hunter wrote:
Alex Young wrote:
class String - RDoc Documentation says this:
"cat o' 9 tails" =~ '\d' #=> nil
I get this:
irb(main):001:0> "cat o' 9 tails" =~ '\d'
TypeError: type mismatch: String given
from (irb):1:in `=~'
from (irb):1
$ ruby -v
ruby 1.8.4 (2005-12-24) [i386-mswin32]
Any clues?
Use a regexp:
irb(main):004:0> "cat o' 9 tails" =~ /\d/
=> 7
That's not the point. Why is what I'm seeing different to what's in the docs? They explicitly say I should be able to use a string there, and I've just wasted half an hour tracking that bug down because of that.
···
--
Alex
Logan Capaldo wrote:
String#=~ used to automagically convert the second arg into a regexp. It doesn't do that anymore.
Ah, ok. That makes sense. Why was it changed?
···
--
Alex
I'd really like similar behavior to be added back in. For example,
converting to a Regexp, yes, but instead: 'foo' =~ 'o' would convert
'o' such as: Regexp.new(Regexp.escape('o'))
···
On 6/25/06, Logan Capaldo <logancapaldo@gmail.com> wrote:
On Jun 24, 2006, at 1:51 PM, Alex Young wrote:
> class String - RDoc Documentation says this:
>
> "cat o' 9 tails" =~ '\d' #=> nil
>
> I get this:
>
> irb(main):001:0> "cat o' 9 tails" =~ '\d'
> TypeError: type mismatch: String given
> from (irb):1:in `=~'
> from (irb):1
>
> $ ruby -v
> ruby 1.8.4 (2005-12-24) [i386-mswin32]
>
> Any clues?
>
> --
> Alex
>
String#=~ used to automagically convert the second arg into a regexp.
It doesn't do that anymore.
--
Matt