Douglas Livingstone wrote:
> On Mon, 21 Mar 2005 02:59:53 +0900, Ilias Lazaridis <ilias / lazaridis.com> wrote:
> 
>>Martin DeMello wrote:
>>
>>>Ilias Lazaridis <ilias / lazaridis.com> wrote:
>>>
>>># __FILE__ == $0 means that the program is being run directly
>>># rather than 'require'd from another file
>>>
>>>if __FILE__ == $0
>>>  talker = Talker.new
>>>  talker.sayHello
>>>end
>>
>>Assuming I placethe code into the file "talker.rb".
>>
>>from the command-line, i like to start it, e.g. with "ruby talker.rb"
>>
>>I miss a "main" directive / function / object.
> 
> You can think of the whole file as "main". The code will be read from
> top to bottom.

I understand.

This means that ruby is _not_ strictly Object Oriented.

And this means that I can drop the "if __FILE__ [...]" construct.

I like both points.

-

I assume I can launch my application with "ruby talker.rb".

>>># one-pass interpreter, and you can reopen classes
>>># so let's just continue
>>
>>[sidenote: I don't understand this]
> 
> Example:
> 
> # first time setting the class
> class Talker
>   attr_accessor :name
> 	
>   def initialize(name)
>     @name = name
>   end
> 	
> end
> 
> talker = Talker.new('Bob')
> puts talker.name
> 
> # reopen the class to add sayYourName
> class Talker
>   def sayYourName
>     puts @name
>   end
> end
> 
> talker.sayYourName
> 
> 
> The output is:
> 
> Bob
> Bob

[I think I understand, but will postpone this construct]

>>>class Talker
>>>  attr_accessor :name, :age
>>
>>can I write?:
>>
>>attr_accessor :name
>>attr_accessor :age
> 
> yes

ok

>>>   def initialize(name, age)
>>>     @name, @age = name, age
>>>   end
>>
>>Is this the constructor?
>>
>>I assume I can write
>>
>>    def initialize(name, age)
>>      @name = name
>>      @age  = age
>>    end
> 
> yes

ok

>>>  # following the spec, though say_name is more rubyish
>>>  def sayYourName
>>>    puts @name
>>>  end
>>
>>can I write?: def sayYourName puts @name end
> 
> You need to add semicolons if you want to put more than one line on a line:
> 
> def sayYourName; puts @name; end

ok

> hth,
> Douglas

..

-- 
http://lazaridis.com