From: Trans Date: 2006-08-29T13:55:04+09:00 Subject: Re: Partial append_features? Ola Bini wrote: > Hi, > > I'm looking for a way to copy methods from a Module, or specify more > directly which methods get included in a class. More or less, I would > like to be able to do something like this: > > module Foo > def do_one_thing > end > def do_second > end > def do_third > end > end > > class Bar > append_from Foo, :do_second, :do_third > end > > or > module Baz > append_from Foo, :do_second, :do_third > end > > and I would have a module Baz which could be included, without having > do_one_thing included. > > Is this possible in Ruby right now? My first approach was to get the > UnboundMethod instance_method from the Module, but I couldn't find a way > to attach these to an unrelated class since UnboundMethod must have a > is_a?-relationship with the binding object. Try Facets' module/integrate.rb Here's the doc: # Using integrate is just like using include except the # module included is a reconstruction of the one given # altered via commands in the block. # # Convenient commands available are: #rename, #redef, # #remove, #nodef and #wrap. But any module method # can be used. # # module W # def q ; "q" ; end # def y ; "y" ; end # end # # class X # integrate W do # nodef :y # end # end # # x = X.new # x.q #=> "q" # x.y #=> missing method error # # This is like #revisal, but #revisal only # returns the reconstructred module. It does not # include it. http://facets.rubyforge.org T.