On Thu, 24 Mar 2005 10:59:50 +0900, Ilias Lazaridis <ilias / lazaridis.com> wrote:
> Martin DeMello wrote:
> > # here's your basic talker class
> >
> > class Talker
> >   def sayHello
> >     puts "Hello world"
> >   end
> > end
> 
> I will make a slight addition:
> 
> The application main code will be alternatively entered in a seperate
> file, main.rb:
> 
> >   talker = Talker.new
> >   talker.sayHello
> 
> How does "main.rb" gets knowledge about "talker.rb" ?

Put the code for the Talker class in a separate file then 'require'
that file in main.rb. For example, if the Talker class were in
talker.rb then I'd have:

  require 'talker'

  talker = Talker.new
  talker.sayHello

for my main.rb. Note that the require statement does not need the .rb
suffix on the file containing the class.


> >   # string interpolation in action - the bit between the #{} can be
> >   # any valid expression; to_s will be called on the result and
> >   # interpolated into the string
> >   def sayHelloAdvanced
> >     puts "#{thisMethodName}: Hello World"
> >   end
> 
> "#" is used as a comment marker _and_ partly within code.
> 
> Can I use another comment marker?

No. To my knowledge there is only the one comment syntax in ruby.

> Can I write "puts "#{thisMethodName}: Hello World"" in an different
> manner, without the use of "#"?

Sure. #{thisMethodName} in a string literal simply calls .to_s on the
enclosed expression and inserts it at the designated location. So we
can pull that out such:

  puts thisMethodName.to_s + ": Hello World"

The + operator performs concatenation when its arguments are strings.

Jacob Fugal