[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

object.inspect not working

Navya Amerineni

5/28/2005 8:16:00 PM

hi all,

i am very new to Ruby.
I stared writing very basic programs
The below is one of my program
class Song
def initialize(name, artist, duration)
@name=name
@artist=artist
@duration=duration
end
def myclass_function
puts "this is my first class"
end
end
class1=Song.new("Navya","Teja",540)
class1.myclass_function
class1.inspect


i am not getting any any output for the statement
class1.inspect

what might be possible correction
please help

Navya.




__________________________________
Do you Yahoo!?
Yahoo! Small Business - Try our new Resources site
http://smallbusiness.yahoo.com/...


3 Answers

Patrik Maunus

5/28/2005 8:27:00 PM

0

On Sun, 29 May 2005 05:15:35 +0900, Navya Amerineni wrote:

Object#inspect returns a string, it does not print out the result.
try:
puts class1.inspect


> class1=Song.new("Navya","Teja",540)
> class1.myclass_function
> class1.inspect
>
>
> i am not getting any any output for the statement
> class1.inspect
>
> what might be possible correction
> please help

James Gray

5/28/2005 8:33:00 PM

0

On May 28, 2005, at 3:15 PM, Navya Amerineni wrote:

> hi all,
>
> i am very new to Ruby.
> I stared writing very basic programs
> The below is one of my program
> class Song
> def initialize(name, artist, duration)
> @name=name
> @artist=artist
> @duration=duration
> end
> def myclass_function
> puts "this is my first class"
> end
> end
> class1=Song.new("Navya","Teja",540)
> class1.myclass_function
> class1.inspect
>
>
> i am not getting any any output for the statement
> class1.inspect

inspect() returns a String which is often used to contain useful
debugging information. inspect() does not print that String.

> what might be possible correction

You need to ask Ruby to print the String to the screen. Try changing
the last line to:

puts class1.inspect

Hope that helps.

James Edward Gray II



Caio Tiago Oliveira

5/29/2005 12:27:00 AM

0

James Edward Gray II, 28-05-2005 17:33:
> On May 28, 2005, at 3:15 PM, Navya Amerineni wrote:
>
>> hi all,
>>
>> i am very new to Ruby.
>> I stared writing very basic programs
>> The below is one of my program
>> class Song
>> def initialize(name, artist, duration)
>> @name=name
>> @artist=artist
>> @duration=duration
>> end
>> def myclass_function
>> puts "this is my first class"
>> end
>> end
>> class1=Song.new("Navya","Teja",540)
>> class1.myclass_function
>> class1.inspect
>>
>>
>> i am not getting any any output for the statement
>> class1.inspect
>
>
> inspect() returns a String which is often used to contain useful
> debugging information. inspect() does not print that String.
>
>> what might be possible correction
>
>
> You need to ask Ruby to print the String to the screen. Try changing
> the last line to:
>
> puts class1.inspect

or even

p class1


:)




____________________________________________________
Yahoo! Mail, cada vez melhor: agora com 1GB de espa?o gr?tis! http://mail.ya...