Forum: Ruby include_class,how to define it?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ba608f20b6707017d9812b9b3f1406e3?d=identicon&s=25 gpy good (gpygood)
on 2007-06-29 09:31
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
97550977337c9f0a0e1a9553e55bfaa0?d=identicon&s=25 Jano Svitok (Guest)
on 2007-06-29 09:53
(Received via mailing list)
On 6/29/07, gz zz <gpygood@126.com> wrote:
>   def 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.
Ba608f20b6707017d9812b9b3f1406e3?d=identicon&s=25 gpy good (gpygood)
on 2007-06-29 10:34
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
This topic is locked and can not be replied to.