DEV Community

loading...

#pretty_print_instance_variables

Kelly Stannard
Developer. Design pattern enthusiast. Tilting at Agile practices.
・1 min read

I was trying to learn about pretty_print, as that is how Pry displays objects to stdout, when I learned about this method. It is pretty simple so I will just show an example.

class MyClass
  attr_accessor :long, :list, :of, :attrs
end

pp MyClass.new
#<MyClass:0xobject_id @long=nil, @list=nil, @of=nil, @attrs=nil>

class MyClass
  def pretty_print_instance_variables
    [:@long]
  end
end

pp MyClass.new
#<MyClass:0xobject_id @long=nil>

Discussion (0)