On Mon, February 21, 2005 10:17 pm, Panagiotis Karvounis said:
> What about this one?
>
> For your help Greek words translation:
>
>
> ypoxrewsi=duty
> topos=place
> diarkeia=duration
> skopos=subject
> hmera=day(date)
> wra=time
> emfanisi=print
>
> Thanks so much for helping me.
>
>
>
> On Tue, 22 Feb 2005 07:08:44 +0900, Austin Ziegler <halostatue / gmail.com>
> wrote:
>> On Tue, 22 Feb 2005 07:01:59 +0900, Panagiotis Karvounis
>> <pkarvou / gmail.com> wrote:
>> > I am not trying sth special.I am testing language features that I
>> > use with Java.
>> >
>> > I was trying to use initialize more than once (think Java-default
>> > constructor, other with one argument etc...)
>> >
>> > Example with Java:
>> >
>> > public class Rectangle
>> > {
>> >   public int a,b;
>> >   public Rectangle()
>> >   {
>> >     a=0;
>> >     b=0;
>> >   }
>> >   public Rectangle(int c,int d)
>> >   {
>> >   a=c;
>> >   b=d;
>> >   }
>> > }
>>
>> > So I tried:
>> > class Rectangle
>> >   def initialize
>> >     @a=0
>> >     @b=0
>> >   end
>> >
>> >   def initialize(c,d)
>> >     @a=c
>> >     @b=d
>> >   end
>> > end
>>
>>  class Rectangle
>>    def initialize(a = 0, b = 0)
>>      @a = a
>>      @b = b
>>    end
>>  end
>>
>> That will work very well for you.
>>
>> You can do any number of other things like this that I find work as
>> well or better than actual argument overloading, mostly because Ruby
>> is dynamically typed.

What I would do is just use 'one' constructor,

def initialize(topos, diarkeia, skopos, hmera, wra)
 @topos, @diarkeia, @skopos = topos, diarkeia, skopos
 @hmera, @wra               = hmera, wra
end

and do this:

e = Ypoxrewsi.new("Spiti", 1, "Ruby", Pdate.new(21,2,2005), Ptime.new(18,2))
a = Pdate.new(21,2,2005)
b = Ptime.new(18,2)
f = Ypoxrewsi.new("Spiti", 1, "Ruby", a, b)


You could also use named arguments like this:

require "TimeDateTools"
include MyTools

class Ypoxrewsi

  def initialize(topos, diarkeia, skopos, hsh)
    # Normal assignments, always present
    @topos, @diarkeia, @skopos = topos, diarkeia, skopos

    # Extract the rest from hash (assumes all necessary are given).
    if hsh.has_key? :hmera
      @hmera, @wra = hsh[:hmera], hsh[:wra]
    else
      @hmera = Pdate.new(hsh[:day], hsh[:month], hsh[:year])
      @wra   = Ptime.new(hsh[:hour], hsh[:minute])
    end
  end

  # ...
end


c = Ypaxrewsi.new("Livadeia", 2, "Syskepsi",
                  :day => 25, :month => 8, :year => 1983,
                  :hour => 19, :minute => 30)
c.emfanisi

a = Pdate.new(21,2,2005)
b = Ptime.new(18,2)

d = Ypoxrewsi.new("Spiti", 1,"Ruby",
                  :hmera => a, :wra => b)
d.emfanisi


>> -austin
>> --
>> Austin Ziegler * halostatue / gmail.com
>>               * Alternate: austin / halostatue.ca

E