Sorry about the delay… you know how it is!
On Jun 25, 8:30 am, Robert K. [email protected] wrote:
lib/foo/baz.rb
require ‘foo’
class Foo::Baz
…
end
Not always feasible, especially if you are loading a whole directory
of “pluggable” files. In which case you either bottom require of use
a separate file. I just as soon not have to worry about it either way
and if class and module where the same type of object then we wouldn’t
have to.
Alternative:
lib/foo.rb
class Foo
…
autoload :Baz, ‘foo/baz’
end
I do not ever use autoload, as much as I might like to. It has a known
bug --it will not use a customized require. I used a customized
require in my development environment, so it is useless to me. (and
really the one thing that pisses the most… but thats’ another story)
Why is not including their singleton methods a strong limitation?
end
and be done so I suspect you mean something else.
Well that’s one thing. But look what happens:
class Y < X
def self.wok
“ain’t going to happen”
end
end
You’ve strapped the implementation to a specific module, so there is
no way to override behavior in a subclass (short of overriding every
method that uses #wok).
and apply it at the same time, e.g.
I personally would separate the DSL out into another module because
that is more modular. Not all classes might need smart attribute
“name” so this would be a better choice IMHO.
Well, you could do that. But that’s not really the main issue.
Probably the most significant issue is with super:
module M
def self.x; “M”; end
end
class X
include M
def self.x
super
end
end
You get an error. If it wasn’t for this class inheritable attributes
would be completely trivial to implement.
Another more clear case is where the DSL defines a method that uses
another method the instance level as an overridable piece of
functionality.
module DSL
def self.smart_attribute(sym)
class_eval “def #{sym}; puts message + ’ ’ + @#{sym}.to_s; end”
end
# Default message is 'Look Ma, a smart:'.
def message
'Look Ma, a smart:'
end
end
Not being able to do this, you have to do more difficult meta-
programming tricks to achieve the same result.
base.extend self
for this (which might be due to the different tasks we tackle with
Ruby).
To me, not propagating them is “not obvious” --anything that creates
more work for me, when the alternative has no significant issues,
seems “not obvious”
- Using tools for conceptually different cases does not require that
their be physically different tools for each case. I wrench is just as
good for tightening a nut as it is for loosening one. If I had to use
two separate tools it would be quite annoying.
I believe this is a bad analogy. If at all you would have to take
“tightening and loosing nuts” and “hammering”. In that case it’s
quite obvious that you would not normally use the same tool for the
job.
I believe this points into the right direction. I’m not doing as much
meta programming - probably because I am not involved in creating
frameworks in Ruby. I rather use the language to solve day to day
problems. So far my need for DSL’s has been scarce. So where were
you really hurt by not automatically propagating class methods? I
can’t think of a case but obviously you have one in mind.
Look at Anise, look at Facets Inheritor. And wherever you find the
ClassMethods hack, that is a case, and there are many of those around.