DEV Community

Kelly Stannard
Kelly Stannard

Posted on

3 2

#pretty_print_instance_variables

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>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More