Sha256: 407bce117dc01e8bd91a2f01e4bcebdc49fa12462afd10895b8b61eaaa49f0ff

Contents?: true

Size: 1.43 KB

Versions: 8

Compression:

Stored size: 1.43 KB

Contents

require 'date'

module Mocha
  module Inspect
    module ObjectMethods
      def mocha_inspect
        address = __id__ * 2
        address += 0x100000000 if address < 0
        inspect =~ /#</ ? "#<#{self.class}:0x#{Kernel.format('%<address>x', address: address)}>" : inspect
      end
    end

    module ArrayMethods
      def mocha_inspect(wrapped = true)
        unwrapped = collect(&:mocha_inspect).join(', ')
        wrapped ? "[#{unwrapped}]" : unwrapped
      end
    end

    module HashMethods
      def mocha_inspect
        if Hash.ruby2_keywords_hash?(self)
          collect do |key, value|
            case key
            when Symbol
              "#{key}: #{value.mocha_inspect}"
            else
              "#{key.mocha_inspect} => #{value.mocha_inspect}"
            end
          end.join(', ')
        else
          unwrapped = collect { |key, value| "#{key.mocha_inspect} => #{value.mocha_inspect}" }.join(', ')
          "{#{unwrapped}}"
        end
      end
    end

    module TimeMethods
      def mocha_inspect
        "#{inspect} (#{to_f} secs)"
      end
    end

    module DateMethods
      def mocha_inspect
        to_s
      end
    end
  end
end

class Object
  include Mocha::Inspect::ObjectMethods
end

class Array
  include Mocha::Inspect::ArrayMethods
end

class Hash
  include Mocha::Inspect::HashMethods
end

class Time
  include Mocha::Inspect::TimeMethods
end

class Date
  include Mocha::Inspect::DateMethods
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mocha-2.6.0 lib/mocha/inspect.rb
mocha-2.5.0 lib/mocha/inspect.rb
mocha-2.4.5 lib/mocha/inspect.rb
mocha-2.4.4 lib/mocha/inspect.rb
mocha-2.4.3 lib/mocha/inspect.rb
mocha-2.4.2 lib/mocha/inspect.rb
mocha-2.4.1 lib/mocha/inspect.rb
mocha-2.4.0 lib/mocha/inspect.rb