til

Today I Learned: collection of notes, tips and tricks and stuff I learn from day to day working with computers and technology as a developer

View project on GitHub

Dump objects attributes

You can dump a objects attributes using ìnspect and you can even extend it.

Adding an inspect method to your class allows you to define how the class’ attributes are displayed, rather than rely on default output. A lot of classes don’t implement it well, but it can be really useful when debugging. Ruby will fall back to to_s if it can’t find an inspect` method

puts variable.inspect

Do note that this works for all data types, not just objects. And there is even an alternative do see pp.

pp variable

References