4 ms·
I think both camps will feel much happier when something like refinements are added to Ruby. In Perl I can safely localise all my monkey-patching by using dyna
by draegtun 14y ago
I think both camps will feel much happier when something like refinements are added to Ruby.
In Perl I can safely localise all my monkey-patching by using dynamic scoping:
sub today { DateTime->now }
{
no warnings 'redefine';
local *DateTime::now = sub {
DateTime->new( year => 2012, month => 12, day => 24 )
};
# now everything in this scope uses the monkey-patched DateTime::now
say "I'm the stubbed monkey-patched date!" if today->day == 24;
}
say today(); # => DateTime->now()