Print an instance variable?


#1

Is there a way to print out an instance variable (@something) so you can
see:

1: what it contains
2: how it’s mapped together

??


#2

puts @something

??

require ‘pp’

pp @something

I’m not sure about #2, what do you mean?


#3

debug(@something) ?

On 10/01/06, David Mr. removed_email_address@domain.invalid wrote:


Posted via http://www.ruby-forum.com/.


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Rasputin :: Jack of All Trades - Master of Nuns
http://number9.hellooperator.net/


#4

#2 would be table associations. Like if I have a @something that
has_many other @somethings.

Jules J. wrote:

puts @something

??

require ‘pp’

pp @something

I’m not sure about #2, what do you mea


#5

Depending on where you want to know. Setting a breakpoint show a lot.

http://wiki.rubyonrails.com/rails/pages/HowtoDebugWithBreakpoint

When you set a breakpoint in your code and have a terminal connect
simply type
the variable and you got lot’s to read.

Regards,

Gerard.
On Tuesday 10 January 2006 17:04, David Mr. tried to type something
like:

Is there a way to print out an instance variable (@something) so you can
see:

1: what it contains
2: how it’s mapped together

??


“Who cares if it doesn’t do anything? It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process …”

My $Grtz =~ Gerard;
~
:wq!


#6

On Tue, 2006-01-10 at 17:04 +0100, David Mr. wrote:

Is there a way to print out an instance variable (@something) so you can
see:

1: what it contains
2: how it’s mapped together

<%= @foo.inspect %>
will show the contents of @foo. In turn,

if Foo has_many :bars then you will see that .bars is of the proper
class for bars. Beyond that, you can use breakpointers and play with
the environment to your hearts content.

bear in mind, if you @foo.bars.inspect you are calling .bars into
existence, you can’t @foo.inspect and see the content of .bars, since
you haven’t asked for it to exist (to read the data from the database).
If rails/ruby assumed such things it would be infinitely pulling all of
your data from the DB, yeech.

-Matthew B.
removed_email_address@domain.invalid :: 607 227 0871
Resume and Portfolio @ http://madhatted.com


#7

Awesome. That worked great thanks!

Matthew B. wrote:

<%= @foo.inspect %>
will show the contents of @foo. In turn,

if Foo has_many :bars then you will see that .bars is of the proper
class for bars. Beyond that, you can use breakpointers and play with
the environment to your hearts content.