Ah, I see this has made it into an RCR. I think its a good idea, but I beleive the implementation will have to be a bit different than that suggested. Besides, it would certainly be better if Ruby was more "aware" of this capability, then the example implementation allows. The exmaple implementation is also, IMHO, overly verbose. Furthermore, it has a scoping problem with string iterpolation.
def self.append_dynamic_features(base, options)
...
base.module_eval %{
p "#{self}"
...
}
end
Will not result in the self one would normally want.
If the implemenation is improved I am in favor.
T.
I think that should be:
p "\#{self}"
or
p "#{base}"
this way you would get your expected behaviour. IMHO, p "#{self}" gives the expected result.
George
Just pointing to the "traits" mechanism :
Traits give fine control to the including entity over what gets included from a mixin, so you get a similar kind of flexibility than with parameterized includes, but without having to write the mixin in a templatized way.
What do you think ? should I post a separate RCR for traits or is this one the place to discuss it ?
-- Damien
Fair points George. Certainly it is workable and thus useful the way you have implemented. But as an RCR, the implementation should be more integerated into Ruby. IN other words, there should be away to achieve this functionality without the string interpolation.
BTW I have a module method that I think would be better as a paramerterized module:
def key_attributes(*fields)
code = ""
code << "def ==(o) " << fields.map {|f| "self.#{f} == o.#{f}" }.join(" && ") << " end\n"
code << "def eql?(o) " << fields.map {|f| "self.#{f}.eql?(o.#{f})" }.join(" && ") << " end\n"
code << "def hash() " << fields.map {|f| "self.#{f}.hash" }.join(" ^ ") << " end\n"
# puts code
class_eval code
fields
end
So others agree that this is a good use case?
T.
Will not result in the self one would normally want.
If the implemenation is improved I am in favor.
T.
I think that should be:
p "\#{self}"
or
p "#{base}"
this way you would get your expected behaviour. IMHO, p "#{self}" gives the expected result.
George
Just pointing to the "traits" mechanism :
Traits give fine control to the including entity over what gets included from a mixin, so you get a similar kind of flexibility than with parameterized includes, but without having to write the mixin in a templatized way.
What do you think ? should I post a separate RCR for traits or is this one the place to discuss it ?
-- Damien
Fair points George. Certainly it is workable and thus useful the way you have implemented. But as an RCR, the implementation should be more integerated into Ruby. IN other words, there should be away to achieve this functionality without the string interpolation.
BTW I have a module method that I think would be better as a paramerterized module:
So others agree that this is a good use case?
T.