Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

actor.biography now needs to_s for match variables #1

Open
wuffo opened this issue Jan 30, 2010 · 1 comment
Open

actor.biography now needs to_s for match variables #1

wuffo opened this issue Jan 30, 2010 · 1 comment

Comments

@wuffo
Copy link

wuffo commented Jan 30, 2010

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.

@ramsingla
Copy link
Owner

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. :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants