#pretty_print_instance_variables
KW Stannard

KW Stannard @kwstannard

About: Developer. Design pattern enthusiast. Tilting at Agile practices.

Joined:
Sep 9, 2019

#pretty_print_instance_variables

Publish Date: Oct 21 '19
8 0

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

Comments 0 total

    Add comment