"Michael Weller" <michael / gutschi.de> schrieb im Newsbeitrag
news:40112D72.6010107 / gutschi.de...
> Robert Klemme schrieb:
>
> >For me it doesn't work in the same file.  It should always throw as Guy
> >pointed out already.  I guess you might have tested something different
> >(maybe you forgot "< A" in one of the files).
> >
> >
> Here's my "real" code (BlogData.rb):
> <code>
> class Timed
>     attr_reader :time
>     def initialize
>         @time = Time.new # <-- line 23
>     end
> end
>
> class Entry < Timed
>     attr_reader :title, :description
>     def initialize(titleS, descS)
>         super()
>         @title = titleS
>         @description = descS
>         @comments = Array.new
>     end
>     def to_s
>         "E : #{@title} -- #{@description}  [#{@time}]"
>     end
> end
>
> class Comment < Timed
>     attr_reader :text
>     def initialize(commentS)
>         super()
>         @text = commentS
>     end
> end
>
> e = Entry.new('title1','desc1')
> puts e
> </code>
>
> My shell:
>  >ruby BlogData.rb
> E : title1 -- desc1  [Fri Jan 23 15:11:27 Westeurop?ische Normalzeit
2004]
>  >Exit code: 0
>
> And here's another file in the directory (t.rb):
> <code>
> require 'BlogData'
> e = Entry.new('title1','desc1')
> puts e
> </code>
>
> My Shell (with 'puts e' in BlogData.rb deleled):
>  >ruby t.rb
> /BlogData.rb:23:in `initialize': wrong number of arguments(0 for 2)
> (ArgumentError)
>     from ./BlogData.rb:23:in `new'
>     from ./BlogData.rb:23:in `initialize'
>     from ./BlogData.rb:32:in `initialize'
>     from t.rb:17:in `new'
>     from t.rb:17
>  >Exit code: 1

Strange that t.rb is reported to have line 17 while the code above looks
like only three lines.

> It doesn't work if I "require" my code in another file.

And you're 100% sure that the required code is the same as presented
above?  No load path pecularities?  Sorry, I can't believe this - it works
for me:

15:32:54 [blog]: ruby BlogData.rb
E : title1 -- desc1  [Fri Jan 23 15:32:59 GMT+1:00 2004]
15:32:59 [blog]: ruby t.rb
E : title1 -- desc1  [Fri Jan 23 15:33:03 GMT+1:00 2004]
E : title1 -- desc1  [Fri Jan 23 15:33:03 GMT+1:00 2004]
15:33:03 [blog]: cat BlogData.rb
class Timed
    attr_reader :time
    def initialize
        @time = Time.new # <-- line 23
    end
end

class Entry < Timed
    attr_reader :title, :description
    def initialize(titleS, descS)
        super()
        @title = titleS
        @description = descS
        @comments = Array.new
    end
    def to_s
        "E : #{@title} -- #{@description}  [#{@time}]"
    end
end

class Comment < Timed
    attr_reader :text
    def initialize(commentS)
        super()
        @text = commentS
    end
end

e = Entry.new('title1','desc1')
puts e
15:33:09 [blog]: cat t.rb
require 'BlogData'
e = Entry.new('title1','desc1')
puts e
15:33:13 [blog]:

> Writing "def initialize()" or "def initialize" doesn't make a
> difference, does it?

No difference.

    robert