Is there equivalent for PHP's print_r in Ruby / Rails?

前端 未结 8 770
鱼传尺愫
鱼传尺愫 2020-12-08 03:17

In PHP you can do:

print_r($var) or vardump($var)

which prints \"human-readible\" information about variable.

Is there equ

8条回答
  •  无人及你
    2020-12-08 03:25

    Instead of requiring 'pp' and using pp, you can simply do

    p object
    

    Tested example

    require 'pp'
    
    class A
      def initialize
        @a = 'somevar'
        @b = [1,2,3]
        @c = {'var' => 'val'}
      end
    end
    
    a = A.new
    pp a # Gives -> #"val"}>
    p a # Gives -> #"val"}>. No need to require 'pp'
    

提交回复
热议问题