From: Jean Helou Date: 2007-01-05T18:40:38+09:00 Subject: Re: puts returns nil? because you only call say_moo once. x = say_moo 3 the interpreter will resolve and execute the method call and will store the _result_ in x thus say_moo is called once and x is set to the string "Yellow submarine" puts x this will only print the content of x which is a string and won't call say_moo another time did it help ? jean On 1/5/07, Arfon Smith wrote: > Hi, I'm sorry to be asking such a daft question but I need a concept > explaining.... > > > I'm working through the excellent Chris Pine book 'Learn to program' and > I don't get one of the examples he gives. In particular I don't follow > the following example: > > > def say_moo number_of_moos > puts 'mooooooo...' * number_of_moos > 'yellow submarine' > end > > x = say_moo 3 > puts x.capitalize + ', dude...' > puts x + '.' > > Now the output from this is: > > mooooooo...mooooooo...mooooooo > Yellow submarine, dude... > yellow submarine > > ------------- > > OK, so here's the problem, I _don't_ get why it doesn't return the > following: > > > mooooooo...mooooooo...mooooooo > Yellow submarine, dude... > mooooooo...mooooooo...mooooooo > yellow submarine > > ------------- > > Why do we get one set of 'moos' but not a second? > > Sorry for such a newbiee question. > > Cheers > > arfon > > -- > Posted via http://www.ruby-forum.com/. > >