L
Luke Kanies
Hi all,
I've currently got a very flat code structure in a large code base
[1], and I'm looking at redoing the layout to make the functional
lines more obvious. This redesign will add an extra constant to
every class path; e.g., where I might have 'Puppet::Type::User' right
now, I'd have 'Puppet::OSAL::Type::User' in the new layout.
If possible, I'd like to avoid having to type full class paths every
time I talk about a class. I've noticed that Ruby behaves very
differently depending on how I define a class; for instance:
class One
class Two
end
end
will allow Two to use unqualified constants from One, but
class One::Two
end
will not. This is fine for shallow class paths, but it gets annoying
when every single class I define has to look like this:
module Puppet
module OSAL
class Type
class User
...
end
end
end
end
I'd *much* prefer to just write:
module Puppet::OSAL::Type::User
end
But if I do that, then I'll always have to specify the full class
path. I have quite a few classes in Puppet, and having to include
the full wrappers for every constant in the class path would get very
painful, and I would have to be very conscious of load order (because
every class in Puppet::OSAL::Type would either have to specify type's
parent class if there is one, or it would have to be loaded after
Puppet::OSAL::Type was loaded).
Are there semi-standard ways of making deep class paths more
convenient to use?
Thanks,
Luke
1 - http://reductivelabs.com/projects/puppet
I've currently got a very flat code structure in a large code base
[1], and I'm looking at redoing the layout to make the functional
lines more obvious. This redesign will add an extra constant to
every class path; e.g., where I might have 'Puppet::Type::User' right
now, I'd have 'Puppet::OSAL::Type::User' in the new layout.
If possible, I'd like to avoid having to type full class paths every
time I talk about a class. I've noticed that Ruby behaves very
differently depending on how I define a class; for instance:
class One
class Two
end
end
will allow Two to use unqualified constants from One, but
class One::Two
end
will not. This is fine for shallow class paths, but it gets annoying
when every single class I define has to look like this:
module Puppet
module OSAL
class Type
class User
...
end
end
end
end
I'd *much* prefer to just write:
module Puppet::OSAL::Type::User
end
But if I do that, then I'll always have to specify the full class
path. I have quite a few classes in Puppet, and having to include
the full wrappers for every constant in the class path would get very
painful, and I would have to be very conscious of load order (because
every class in Puppet::OSAL::Type would either have to specify type's
parent class if there is one, or it would have to be loaded after
Puppet::OSAL::Type was loaded).
Are there semi-standard ways of making deep class paths more
convenient to use?
Thanks,
Luke
1 - http://reductivelabs.com/projects/puppet