[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

IO output problem

Peter

12/15/2006 1:33:00 AM

I run one of examples of Programming Ruby, code as follows:
------------
class Sone
....
end

song = Sone.new(.., .., ..)
song.inspect
song.to_s
-----------
why I can't see output? where is output of inspect and to_s ?
It outputs to somewhere else? IO object ?

thank you in advance

6 Answers

dblack

12/15/2006 1:39:00 AM

0

Daniel Finnie

12/15/2006 1:39:00 AM

0

First, Song is misspelled to Sone, it seems.

To answer your question, use puts song.to_s to display output. Puts is
technically a method of Kernel, but you can use it as just puts anywhere
in your Ruby program.

Gets does (kind of) the opposite of puts and "gets" what a user at the
command line typed.

Dan

Kevin wrote:
> I run one of examples of Programming Ruby, code as follows:
> ------------
> class Sone
> ...
> end
>
> song = Sone.new(.., .., ..)
> song.inspect
> song.to_s
> -----------
> why I can't see output? where is output of inspect and to_s ?
> It outputs to somewhere else? IO object ?
>
> thank you in advance
>
>
>

Peter

12/15/2006 1:53:00 AM

0

I understand now, thank you both of you
dblack@wobblini.net wrote:
> Hi --
>
> On Fri, 15 Dec 2006, Kevin wrote:
>
> > I run one of examples of Programming Ruby, code as follows:
> > ------------
> > class Sone
> > ...
> > end
> >
> > song = Sone.new(.., .., ..)
> > song.inspect
> > song.to_s
> > -----------
> > why I can't see output? where is output of inspect and to_s ?
> > It outputs to somewhere else? IO object ?
>
> inspect and to_s just produce strings. To see them, you have to print
> them :-) In fact, there are some handy methods for this:
>
> p song # automatically calls inspect
> puts song # automatically calls to_s
>
> Also, if you are working in irb (the interactive Ruby terminal),
> you'll see the value of every expression you type in. So in irb, if
> your expression evaluates to a string, you'll see the string without
> having to explicitly ask for it to be printed.
>
>
> David
>
> --
> Q. What's a good holiday present for the serious Rails developer?
> A. RUBY FOR RAILS by David A. Black (http://www.manning...)
> aka The Ruby book for Rails developers!
> Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
> A. Ruby Power and Light, LLC (http://www.r...)

x1

12/15/2006 2:14:00 AM

0

It's been a while since I've read that example but for some reason, I
remember thinking it was just an example to show how Ruby's object
orientation worked... not a real functional example. Perhaps it was
and I completely missed it. Dunno..

On 12/14/06, Kevin <coscpp@gmail.com> wrote:
> I understand now, thank you both of you
> dblack@wobblini.net wrote:
> > Hi --
> >
> > On Fri, 15 Dec 2006, Kevin wrote:
> >
> > > I run one of examples of Programming Ruby, code as follows:
> > > ------------
> > > class Sone
> > > ...
> > > end
> > >
> > > song = Sone.new(.., .., ..)
> > > song.inspect
> > > song.to_s
> > > -----------
> > > why I can't see output? where is output of inspect and to_s ?
> > > It outputs to somewhere else? IO object ?
> >
> > inspect and to_s just produce strings. To see them, you have to print
> > them :-) In fact, there are some handy methods for this:
> >
> > p song # automatically calls inspect
> > puts song # automatically calls to_s
> >
> > Also, if you are working in irb (the interactive Ruby terminal),
> > you'll see the value of every expression you type in. So in irb, if
> > your expression evaluates to a string, you'll see the string without
> > having to explicitly ask for it to be printed.
> >
> >
> > David
> >
> > --
> > Q. What's a good holiday present for the serious Rails developer?
> > A. RUBY FOR RAILS by David A. Black (http://www.manning...)
> > aka The Ruby book for Rails developers!
> > Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
> > A. Ruby Power and Light, LLC (http://www.r...)
>
>
>

Daniel Finnie

12/15/2006 2:19:00 AM

0

I think it's from Programming Ruby: The Pragmatic Programmer's Guide.
http://www.rubycentral.com/book/tut_th...

dan

x1 wrote:
> It's been a while since I've read that example but for some reason, I
> remember thinking it was just an example to show how Ruby's object
> orientation worked... not a real functional example. Perhaps it was
> and I completely missed it. Dunno..
>
> On 12/14/06, Kevin <coscpp@gmail.com> wrote:
>> I understand now, thank you both of you
>> dblack@wobblini.net wrote:
>> > Hi --
>> >
>> > On Fri, 15 Dec 2006, Kevin wrote:
>> >
>> > > I run one of examples of Programming Ruby, code as follows:
>> > > ------------
>> > > class Sone
>> > > ...
>> > > end
>> > >
>> > > song = Sone.new(.., .., ..)
>> > > song.inspect
>> > > song.to_s
>> > > -----------
>> > > why I can't see output? where is output of inspect and to_s ?
>> > > It outputs to somewhere else? IO object ?
>> >
>> > inspect and to_s just produce strings. To see them, you have to print
>> > them :-) In fact, there are some handy methods for this:
>> >
>> > p song # automatically calls inspect
>> > puts song # automatically calls to_s
>> >
>> > Also, if you are working in irb (the interactive Ruby terminal),
>> > you'll see the value of every expression you type in. So in irb, if
>> > your expression evaluates to a string, you'll see the string without
>> > having to explicitly ask for it to be printed.
>> >
>> >
>> > David
>> >
>> > --
>> > Q. What's a good holiday present for the serious Rails developer?
>> > A. RUBY FOR RAILS by David A. Black (http://www.manning...)
>> > aka The Ruby book for Rails developers!
>> > Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
>> > A. Ruby Power and Light, LLC (http://www.r...)
>>
>>
>>
>
>

dblack

12/15/2006 2:45:00 AM

0