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 ?? -- Posted via http://www.ruby-forum.com/.
puts @something ?? require ''pp'' pp @something I''m not sure about #2, what do you mean? -- Posted via http://www.ruby-forum.com/.
debug(@something) ? On 10/01/06, David Mr. <dave@pezians.com> 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 > > ?? > > > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Rasputin :: Jack of All Trades - Master of Nuns http://number9.hellooperator.net/
#2 would be table associations. Like if I have a @something that has_many other @somethings. Jules Jacobs wrote:> puts @something > > ?? > > require ''pp'' > > pp @something > > I''m not sure about #2, what do you mea-- Posted via http://www.ruby-forum.com/.
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 Beale mixonic@synitech.com :: 607 227 0871 Resume and Portfolio @ http://madhatted.com
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!
Awesome. That worked great thanks! Matthew Beale 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.-- Posted via http://www.ruby-forum.com/.