Module: Deep::Hash::Struct::PP::Wrapper

Included in:
Wrapper
Defined in:
lib/deep/hash/struct/pp/wrapper.rb

Instance Method Summary collapse

Instance Method Details

#inspectObject



6
7
8
9
# File 'lib/deep/hash/struct/pp/wrapper.rb', line 6

def inspect
  v = blank? ? nil : " #{to_h}"
  "#<#{self.class.name.split("::").last}#{v}>"
end

#pretty_print(q) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/deep/hash/struct/pp/wrapper.rb', line 11

def pretty_print(q)
  q.group(2, "#(#{self.class.name}:#{sprintf("0x%x", object_id)} {", "})") do
    q.breakable

    q.group(2, "{", "}") do
      q.breakable
      pretty_print_cycle(q)
    end

    q.breakable
  end
end

#pretty_print_cycle(q, hash = to_h) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/deep/hash/struct/pp/wrapper.rb', line 24

def pretty_print_cycle(q, hash = to_h)
  q.seplist(hash) do |k, v|
    q.text ":#{k} =>"
    if [String, Integer].include?(v.class)
      q.pp v
    else
      q.group(2, "{", "}") do
        q.breakable
        pretty_print_cycle(q, v)
      end
    end
  end
end