Jian Lin wrote:
> When it is RoR, we can use ActiveRecord's attributes method to get a
> hash for a record's column name and values.  How about if it is just an
> object in Ruby, and we want to print out all instance variables to
> debug, while the inspect() method doesn't print everything out, is there
> a way to print out all instance variables (for any object)
> automatically, for example, to debug the code?  thanks.

I just use the following irb command:
   def instance_var(obj)
     obj.instance_variables.map {|e| [e, obj.instance_variable_get(e)] }
   end
If you define the irb command as a boson command, you get a nice ascii 
table of an object's instance variables: 
http://tagaholic.me/2009/11/07/ruby-reference-commands-with-boson.html#object_instance_variables
-- 
Posted via http://www.ruby-forum.com/.