Module: Ray::PP

Overview

Module containing helpers to implement pretty print

Instance Method Summary collapse

Instance Method Details

#pretty_print_attributes(q, attributes) ⇒ Object

Parameters:

  • q (PrettyPrint)

    Object used for pretty printing

  • attributes (Array<String>)

    Methods to call and to print the result of



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ray/pp.rb', line 7

def pretty_print_attributes(q, attributes)
  id = "%x" % (__id__ * 2)
  id.sub!(/\Af(?=[[:xdigit:]]{2}+\z)/, '') if id.sub!(/\A\.\./, '')

  klass = self.class.pretty_inspect.chomp

  q.group(2, "\#<#{klass}:0x#{id}", '>') do
    q.seplist(attributes, lambda { q.text ',' }) do |key|
      q.breakable

      q.text key.to_s
      q.text '='

      q.group(2) do
        q.breakable ''
        q.pp send(key)
      end
    end
  end
end