I am trying to get hpricot to work from within rails and ran into this
peculiarity. I had a situation where the script runs fine if run as a
ruby script but bombs if called from within rails (as a method of a
model). After some debugging, it came down to this …
Fire up script\console from the root directory of a rails project -
Loading development environment.
expr = “title”
=> “title”m = expr.match(/(^[#.]?)([a-z0-9]*)/)
=> #MatchData:0xb78d1370$’
=> nilm.post_match
=> “”
$’ and m.post_match are different.
Do the same in irb -
irb(main):001:0> expr = “title”
=> “title”
irb(main):002:0> m = expr.match(/(^[#.]?)([a-z0-9]*)/)
=> #MatchData:0xb7c07b48
irb(main):003:0> $’
=> “”
irb(main):004:0> m.post_match
=> “”
$’ and m.post_match are the same.
Ironically if you test this on windows results are script\console are
identical to those of irb. But for Mac or Ubuntu I see the above
behavior.
Tested with ruby 1.8.4.
questions -
- Is this expected behavior?
- Can you suggest a workaround ? I would prefer not to touch the gem
code in hpricot – unless it is the only alternative.
- Chet