Forum: Ruby on Rails print an instance variable?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dave C. (Guest)
on 2006-01-10 18:04
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

??
Jules J. (Guest)
on 2006-01-10 18:06
puts @something

??

require 'pp'

pp @something

I'm not sure about #2, what do you mean?
Dick D. (Guest)
on 2006-01-10 18:08
(Received via mailing list)
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/
Dave C. (Guest)
on 2006-01-10 18:18
#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
Matthew B. (Guest)
on 2006-01-10 18:29
(Received via mailing list)
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

<pre><%= @foo.inspect %></pre> 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
Gerard (Guest)
on 2006-01-10 18:32
(Received via mailing list)
Depending on where you want to know. Setting a breakpoint show a lot.

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

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!
Dave C. (Guest)
on 2006-01-10 19:27
Awesome. That worked great thanks!

Matthew B. wrote:
> <pre><%= @foo.inspect %></pre> 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.
This topic is locked and can not be replied to.