Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> it reminds me of other languages where it's global (JavaScript)

Ew, I didn't realise JS had them and implemented them like that. It's supposed to remind you of Perl, which probably made more sense 20 years ago.

> It get's confusing. And even as a local it is still bad. How is it that the =~ operator can assign local variables? Can other method calls do the same? If not, why not?

Actually, they're not locals, they're "virtual variables", going by the code. You can make your own using the C API - they just call back into a function:

    rb_define_virtual_variable("$&", last_match_getter, 0);
Same way things like $LOADED_FEATURES, $_ and $SAFE get managed. It's probably just as well it's not exposed Ruby-side ;)


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: