P
Peter Seebach
I am trying to figure out what the cleanest way is to express a class that has
subclasses.
Imagine, if you will:
class Foo
def initialize
@bar = Foo::Bar.new(self)
end
end
class Foo::Bar
def initialize(foo)
@foo = foo
end
end
Is that a good rubyish way to do this? If I put Foo::Bar in
its own file, should foo.rb be responsible for requiring it?
What originally got me thinking was that my habit is to put requires,
includes, and such at the top of the file... But then the
declaration "class Foo::Bar" refers to an undefined constant.
Of course, I can write:
class Foo
end
require 'foo/bar.rb'
Is there a clear preference here in Ruby Style?
-s
subclasses.
Imagine, if you will:
class Foo
def initialize
@bar = Foo::Bar.new(self)
end
end
class Foo::Bar
def initialize(foo)
@foo = foo
end
end
Is that a good rubyish way to do this? If I put Foo::Bar in
its own file, should foo.rb be responsible for requiring it?
What originally got me thinking was that my habit is to put requires,
includes, and such at the top of the file... But then the
declaration "class Foo::Bar" refers to an undefined constant.
Of course, I can write:
class Foo
end
require 'foo/bar.rb'
Is there a clear preference here in Ruby Style?
-s