Ruby: “string not matched”

January 3, 2008 at 9:35

Filed under: Computing — Pistos @ 09:35

I was debugging a Reby script and came across a most unusual error:

Reby error: string not matched
chanstats.rb:43:in `[]=’

Line 43 was:

@stats[ channel ][ :size_record ] ||= 0

which looks rather innocuous. I have a couple Hashes, one nested in the other. Or so I thought… Apparently, I had mistakenly initialized @stats with a string instead of a Hash. Testing in irb, everything becomes clear:

irb(main):001:0> s = "string"
=> "string"
irb(main):006:0> s[ 'hi' ] = 'foo'
IndexError: string not matched
        from (irb):6:in `[]='

I hope this helps people who can’t figure out why they’re getting “string not matched”.

Share This
Powered by WordPress.
Close
E-mail It
Socialized through Gregarious 42