4 ms·
> Oh my god, it assigns a global(?)/magic variable as a side effect. Magic locals. You weren't actually unsure if they were global, right?
by Freaky 13y ago
> Oh my god, it assigns a global(?)/magic variable as a side effect.
Magic locals. You weren't actually unsure if they were global, right?
- panzi 13y agoYeah I know it's a local, but it reminds me of other languages where it's global (JavaScript). 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? Why this special status?
- Freaky 13y ago> 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 ;)