Class: Tracer::Base::LimitedPP

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_tracer/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max) ⇒ LimitedPP

Returns a new instance of LimitedPP.



28
29
30
31
32
# File 'lib/ruby_tracer/base.rb', line 28

def initialize(max)
  @max = max
  @cnt = 0
  @buf = String.new
end

Instance Attribute Details

#bufObject (readonly)

Returns the value of attribute buf.



26
27
28
# File 'lib/ruby_tracer/base.rb', line 26

def buf
  @buf
end

Class Method Details

.pp(obj, max) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/ruby_tracer/base.rb', line 18

def self.pp(obj, max)
  out = self.new(max)
  catch out do
    PP.singleline_pp(obj, out)
  end
  out.buf
end

Instance Method Details

#<<(other) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/ruby_tracer/base.rb', line 34

def <<(other)
  @buf << other

  if @buf.size >= @max
    @buf = @buf[0..@max] + "..."
    throw self
  end
end