Class: Test::Unit::Assertions::AssertionMessage::HashInspector
- Inherits:
-
Object
- Object
- Test::Unit::Assertions::AssertionMessage::HashInspector
- Defined in:
- lib/test/unit/assertions.rb
Class Method Summary collapse
Instance Method Summary collapse
- #each_pair ⇒ Object
-
#initialize(hash, inspected_objects) ⇒ HashInspector
constructor
A new instance of HashInspector.
- #inspect ⇒ Object
- #pretty_print(q) ⇒ Object
- #pretty_print_cycle(q) ⇒ Object
Constructor Details
#initialize(hash, inspected_objects) ⇒ HashInspector
Returns a new instance of HashInspector.
1599 1600 1601 1602 1603 1604 1605 1606 1607 |
# File 'lib/test/unit/assertions.rb', line 1599 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
1594 1595 1596 |
# File 'lib/test/unit/assertions.rb', line 1594 def target?(object) object.is_a?(Hash) or object == ENV end |
Instance Method Details
#each_pair ⇒ Object
1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 |
# File 'lib/test/unit/assertions.rb', line 1632 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 ⇒ Object
1609 1610 1611 |
# File 'lib/test/unit/assertions.rb', line 1609 def inspect @hash.inspect end |
#pretty_print(q) ⇒ Object
1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 |
# File 'lib/test/unit/assertions.rb', line 1613 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) ⇒ Object
1628 1629 1630 |
# File 'lib/test/unit/assertions.rb', line 1628 def pretty_print_cycle(q) @hash.pretty_print_cycle(q) end |