Wednesday, December 20, 2017

How do I dump an object's fields to the console?

When I'm running a simple Ruby script, what's the easiest way to dump an object's fields to the console?
I'm looking for something similar to PHP's print_r() that will work with arrays as well.
-----------------------
Possibly:
puts variable.inspect

2 comments:

  1. Để dump vào file log:
    logger.info(variable.inspect)
    hoặc
    Rails.logger.info(variable.inspect)

    ReplyDelete
  2. logger.info "#{variable.inspect}"
    Rails.logger.info "#{variable.inspect}"

    ReplyDelete