You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously, without the plugin, I could do a match or sub on biography directly and the special variables ($1, $&, etc.) would be created. With the plugin, I need to append to_s to biography or else all such variables will be nil - even if the matching succeeds. From the console:
Very interesting observation. The reason of this is because of scope. According to http://www.rubyist.net/~slagell/ruby/globalvars.html. $~ and $_ have local scope even though they seem to be global variables. There is no way in my opinion to populate local scoped $~ and $_ from proxy column. Because automatic local scope will be involved and it would populate the global variables but as soon as that scope closes they will vanish. This is a side-effect of the proxy column. Plus the use of global variables for matching is not very object oriented. :).
Love the plugin.
Previously, without the plugin, I could do a match or sub on biography directly and the special variables ($1, $ &, etc.) would be created. With the plugin, I need to append to_s to biography or else all such variables will be nil - even if the matching succeeds. From the console:
>> actor.biography.match(/(.)/)[0]
actor.biography.match(/(.)/)[0]
=> "H"
>> $1
$1
=> nil
>> actor.biography.to_s.match(/(.)/)[0]
actor.biography.to_s.match(/(.)/)[0]
=> "H"
>> $1
$1
=> "H"
Why does this happen? Can I patch the plugin somehow so that I don't need to_s everywhere?
Thanks.
The text was updated successfully, but these errors were encountered: