T
T. Onoma
So I want to include a module and have methods become part of the class, not
the instance. What do others think of this approach?
class Module
alias :append_instance_features :append_features
def append_features(klass)
if constants.include?("ClassInherit")
klass.extend self::ClassInherit
end
append_instance_features(klass)
end
end
Example:
module MyMod
module ClassInherit
attr_accessor :x
def hix
puts "Hi, #{@x}."
end
end
# ...
end
class A
include MyMod
end
A.x = 'you'
A.hix #=> Hi, you.
the instance. What do others think of this approach?
class Module
alias :append_instance_features :append_features
def append_features(klass)
if constants.include?("ClassInherit")
klass.extend self::ClassInherit
end
append_instance_features(klass)
end
end
Example:
module MyMod
module ClassInherit
attr_accessor :x
def hix
puts "Hi, #{@x}."
end
end
# ...
end
class A
include MyMod
end
A.x = 'you'
A.hix #=> Hi, you.