Programming ruby 1.9- question on page 37

4

4895

not sure what to do which that code at the bottom of page 37. I enter
this code into the command prompt and obviously that isn't right. I
created the folder that I was told to before but I can't remember it
though I did skim a bit to find it. Not clear also on all that syntax
that was used there. I have tried to get a good definition of puts for
a month and have not been able
to. If that is a method why is there another method (say_goodnight
(name)) on the same line?

Brad
 
B

Brian Candler

4895 said:
not sure what to do which that code at the bottom of page 37. I enter
this code into the command prompt and obviously that isn't right. I
created the folder that I was told to before but I can't remember it
though I did skim a bit to find it. Not clear also on all that syntax
that was used there. I have tried to get a good definition of puts for
a month and have not been able
to.

For the benefit of those of use without the 1.9 version of the book, can
you post the code you are trying to run, and the exception you get in
response? I don't think you will be held liable for copyright :)

For a definition of puts see http://www.ruby-doc.org/core/ and look for
'puts' in the right-hand column.

Also the old version of Programming Ruby:
http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_m_kernel.html#Kernel.puts
http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_c_io.html#IO.puts
If that is a method why is there another method (say_goodnight
(name)) on the same line?

Perhaps what you are looking at is one method using the return value of
another as a parameter. For example:

def foo
123
end

puts foo # same as: puts(foo())
 
R

Rick DeNatale

not sure what to do which that code at the bottom of page 37. I enter
this code into the command prompt and obviously that isn't right. I
created the folder that I was told to before but I can't remember it
though I did skim a bit to find it. Not clear also on all that syntax
that was used there. I have tried to get a good definition of puts for
a month and have not been able
to. If that is a method why is there another method (say_goodnight
(name)) on the same line?

Brad

Well the code under the box telling you where to download it (at least
in the pdf version of the book, too lazy to go upstairs to look at the
physical version) is a complete ruby program, either download it or
enter it into a file they suggest intro5.rb,

And then just run it with:

ruby intro5.rb

Alternatively you can paste the text into irb.

puts say_goodnight("John boy")

is the same as

puts(say_goodnight("John boy"))

and invokes the puts function passing the result returned by invoking
say_goodnight("John boy")

puts (p 575) is actually a method defined in the Kernel module which
is available for all instances of subclasses of Object which includes
Kernel.

But at this stage of the book, I believe that the author is just
trying to give you the 'flavor' of Ruby, It might be better to just
read the material, without trying to understand things too deeply.
The picture will get clearer as you progress through the book.

--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,164
Messages
2,570,897
Members
47,439
Latest member
shasuze

Latest Threads

Top