| djberg96 ( @ 2009-10-14 13:05:00 |
| Current mood: |
More random thoughts on mixins, selector namespaces
Ovid's journal got me thinking about the multi-mixin problem again. That got me thinking about selector namespaces again, too.
Consider the current mixin behavior:
module Alpha
def hello
puts "Alpha"
end
end
module Beta
def hello
puts "Beta"
end
end
class Tango
include Alpha
include Beta
end
Tango.new.hello # => "Beta"
Possible solutions:
* First method definition wins
* Last method definition wins, raises a warning
* No one wins, it's an error
And my new, crazy idea:
* First method definition wins, later methods are auto-namespaced
# Let's assume this syntax actually works t = Tango.new t.hello # => "Alpha" (wins, first definition) t.hello:alpha # => "Alpha" (same, but explicit) t.hello:beta # => "Beta" (calls Beta module's method)
Thoughts?
Update: As per the comments below, you could still have "last definition wins" behavior with the above syntax. Also, "alpha" and "beta" should probably be capitalized in the last example above. I dunno, though. I kinda like the lowercase notation in that context.