#pretty_print_instance_variables

github logo ・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>
twitter logo DISCUSS
Classic DEV Post from Jun 24

What If I Want My Website to Last for 100 Years?

Kelly Stannard profile image
Developer. Design pattern enthusiast. Tilting at Agile practices.
Join dev.to

Be a better developer. Free forever.