123456789_123456789_123456789_123456789_123456789_

Class: Test::Unit::Assertions::AssertionMessage::HashInspector

Relationships & Source Files
Inherits: Object
Defined in: lib/test/unit/assertions.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new(hash, inspected_objects) ⇒ HashInspector

[ GitHub ]

  
# File 'lib/test/unit/assertions.rb', line 2190

def initialize(hash, inspected_objects)
  @inspected_objects = inspected_objects
  @hash = {}
  hash.each do |key, value|
    key = Inspector.cached_new(key, @inspected_objects)
    value = Inspector.cached_new(value, @inspected_objects)
    @hash[key] = value
  end
end

Class Method Details

.target?(object) ⇒ Boolean

[ GitHub ]

  
# File 'lib/test/unit/assertions.rb', line 2185

def target?(object)
  object.is_a?(Hash) or ENV.equal?(object)
end

Instance Method Details

#each_pair

[ GitHub ]

  
# File 'lib/test/unit/assertions.rb', line 2223

def each_pair
  keys = @hash.keys
  begin
    keys = keys.sort # FIXME: more cleverly
  rescue ArgumentError
  end
  keys.each do |key|
    yield(key, @hash[key])
  end
end

#inspect

[ GitHub ]

  
# File 'lib/test/unit/assertions.rb', line 2200

def inspect
  @hash.inspect
end

#pretty_print(q)

[ GitHub ]

  
# File 'lib/test/unit/assertions.rb', line 2204

def pretty_print(q)
  q.group(1, '{', '}') do
    q.seplist(self, nil, :each_pair) do |k, v|
      q.group do
        q.pp(k)
        q.text('=>')
        q.group(1) do
          q.breakable('')
          q.pp(v)
        end
      end
    end
  end
end

#pretty_print_cycle(q)

[ GitHub ]

  
# File 'lib/test/unit/assertions.rb', line 2219

def pretty_print_cycle(q)
  @hash.pretty_print_cycle(q)
end