include_class,how to define it?

G

gz zz

Hey,I like ruby's mixin with "include" method,now I want to
include_class,
but,how to define it?
thanks
class Module
def include_class(klass)
end
end

class Foo
def foo
end
end



class Bar
include_class Foo
end


Bar.new.foo
 
J

Jano Svitok

Hey,I like ruby's mixin with "include" method,now I want to
include_class,
but,how to define it?
thanks
class Module
def include_class(klass)
end
end

class Foo
def foo
end
end


class Bar
include_class Foo
end


Bar.new.foo

That's called subclassing, deriving or inheritance.

Just do

class Bar < Foo
end

Bar.new.foo

Note that you can derive from one class only. All others have to be
(included) modules.

J.
 
G

gz zz

If we can define a class method called "source" that can get class's
source ,then
include_class method will be defined

class Foo
include Enumerable
def foo
end
end

Foo.source #=>
# include Enumerable
# def foo
# end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top