PP::PPMethods (Module)

In: pp.rb

Constants

InspectKey = :__inspect_key__

Public Instance methods

[Source]

# File pp.rb, line 225
    def comma_breakable
      text ','
      breakable
    end

[Source]

# File pp.rb, line 186
    def guard_inspect_key
      if Thread.current[InspectKey] == nil
        Thread.current[InspectKey] = []
      end

      save = Thread.current[InspectKey]

      begin
        Thread.current[InspectKey] = []
        yield
      ensure
        Thread.current[InspectKey] = save
      end
    end

[Source]

# File pp.rb, line 221
    def object_address_group(obj, &block)
      group(1, "\#<#{obj.class}:#{("0x%x" % (obj.__id__ * 2)).sub(/\.\.f/, '')}", '>', &block)
    end

[Source]

# File pp.rb, line 217
    def object_group(obj, &block)
      group(1, '#<' + obj.class.name, '>', &block)
    end

[Source]

# File pp.rb, line 201
    def pp(obj)
      id = obj.__id__

      if Thread.current[InspectKey].include? id
        group {obj.pretty_print_cycle self}
        return
      end

      begin
        Thread.current[InspectKey] << id
        group {obj.pretty_print self}
      ensure
        Thread.current[InspectKey].pop unless PP.sharing_detection
      end
    end

[Source]

# File pp.rb, line 258
    def pp_hash(obj)
      group(1, '{', '}') {
        seplist(obj, nil, :each_pair) {|k, v|
          group {
            pp k
            text '=>'
            group(1) {
              breakable ''
              pp v
            }
          }
        }
      }
    end

[Source]

# File pp.rb, line 243
    def pp_object(obj)
      object_address_group(obj) {
        seplist(obj.pretty_print_instance_variables, lambda { text ',' }) {|v|
          breakable
          v = v.to_s if Symbol === v
          text v
          text '='
          group(1) {
            breakable ''
            pp(obj.instance_eval(v))
          }
        }
      }
    end

[Source]

# File pp.rb, line 230
    def seplist(list, sep=nil, iter_method=:each)
      sep ||= lambda { comma_breakable }
      first = true
      list.__send__(iter_method) {|*v|
        if first
          first = false
        else
          sep.call
        end
        yield(*v)
      }
    end

[Validate]