Informatika Mihelac
March 31 2006 php | rails | ruby | tips

Ruby / Rails alternative to PHP print_r() and var_dump()

Both PHP functions provides information about a variable passed as argument. It is often used in development to get quick and human-readable info about array or object. If you are using Rails you can use DebugHelper’s debug(object) helper function. Note that helpers are available only in views. In controllers, models and other Ruby code you can use ‘puts YAML::dump(object)’ method to get readable info about object.

comments feed

9 comments

  1. # On March 31, 2006 at 09:03 AM, Bojan said:
    Additionaly, isset($_GET['param']), can be written as params.include?("confirm").
  2. # On April 20, 2006 at 10:04 AM, tomtt said:
    Try pretty print: require 'pp' pp(ENV)
  3. # On May 18, 2006 at 10:05 AM, afkm_d said:
    Thanks for this hint - nearly got insane...
  4. # On July 05, 2006 at 13:07 PM, Bojan said:
    PHP isset(var1) can be written as: defined? var1
  5. # On October 13, 2006 at 04:10 AM, cies said:
    i used: object.to_json but i'll deffinitly try the above mentioned
  6. # On December 11, 2006 at 10:12 AM, Dustin said:
    As a substitute for print_r, I simply do: [code]p ary[/code]
  7. # On May 11, 2007 at 05:05 AM, opl said:
    I just thought 5 minutes ago: <<what need or print_r really in var_dump ruby i ror is>>. Your post will be VERY useful to me, thanks!!
  8. # On May 11, 2007 at 05:05 AM, opl said:
    (Oops, text badly enclosed was) What I really need is print_r or var_dump in ruby or RoR, let's google "print_r ruby"
  9. # On February 11, 2008 at 05:02 AM, Binny V A said:

    Does ruby(without rails) have any similar function?

Speak your mind:

(Required)

(Required)


(You may use textile in your comments.)

About

I am Bojan Mihelac and this blog is dedicated to share code, thoughts, tools and advices I came up with while working in Informatika Mihelac.

Contact: bmihelac@mihelac.org

RSS feedSubscribe to RSS Feed