Sha256: 121cb6d05c63da736435a8367382bfe1cca310ff7098b955ea7dd3539bb3a13d

Contents?: true

Size: 706 Bytes

Versions: 5

Compression:

Stored size: 706 Bytes

Contents

module Tins
  module TimeDummy
    def self.included(modul)
      class << modul
        alias really_new new

        remove_method :now rescue nil
        remove_method :new rescue nil

        attr_writer :dummy

        def dummy(value = nil)
          if value.nil?
            @dummy
          else
            begin
              old_dummy = @dummy
              @dummy = value
              yield
            ensure
              @dummy = old_dummy
            end
          end
        end

        def new
          if dummy
            dummy.dup
          else
            really_new
          end
        end

        alias now new
      end
      super
    end
  end
end

require 'tins/alias'

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tins-0.4.2 lib/tins/time_dummy.rb
tins-0.4.1 lib/tins/time_dummy.rb
tins-0.4.0 lib/tins/time_dummy.rb
tins-0.3.14 lib/tins/time_dummy.rb
tins-0.3.13 lib/tins/time_dummy.rb