News for hackers. Stuff that matters.
Re:Dependency injection is not a virtue by draegtun on Monday January 07, 2013 @08:41AM (#5020870)
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()

There are no comments on this comment yet.