Forum: Ruby #append_features deprecated?

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.
transfire (Guest)
on 2005-12-03 14:25
(Received via mailing list)
Somone else mentioned this. Is it true?

Thanks,
T.
dave (Guest)
on 2005-12-03 14:48
(Received via mailing list)
Trans wrote:
> Somone else mentioned this. Is it true?

This says Module#included " should be used in preference to
Module.append_features if your code wants to perform some action when a
module is included in another."

http://www.ruby-doc.org/core/classes/Module.html#M000704

Cheers,
Dave
30804046d28e30e9492f5309a57a6c31?d=identicon&s=25 Daniel S. (dasch)
on 2005-12-03 16:43
(Received via mailing list)
Dave Burt wrote:
> Dave
module M
     def self.included(klass)
       puts "Included in #{klass}"
     end
   end

   class A
     include M  # -> Included in A
   end

   class B
     M.append_features(self)  # Nothing
   end

As you can see, Module#append_features doesn't call the .included method
on the module, include does.


Cheers,
Daniel
decoux (Guest)
on 2005-12-03 16:51
(Received via mailing list)
>>>>> "D" == Daniel Schierbeck <daniel.schierbeck@gmail.com> writes:

D> As you can see, Module#append_features doesn't call the .included
method
D> on the module, include does.

 Well, it's best to see it like this :

moulon% cat b.rb
#!/usr/bin/ruby
module M
   def self.included(klass)
      puts "Included in #{klass}"
   end
   def a
      puts "a"
   end
end

class A
   include M
end

A.new.a
moulon%

moulon% ./b.rb
Included in A
a
moulon%

moulon% cat b.rb
#!/usr/bin/ruby
module M
   def self.append_features(klass)
      puts "Included in #{klass}"
   end
   def a
      puts "a"
   end
end

class A
   include M
end

A.new.a
moulon%

moulon% ./b.rb
Included in A
./b.rb:15: undefined method `a' for #<A:0xb7d64b38> (NoMethodError)
moulon%


Guy Decoux
30804046d28e30e9492f5309a57a6c31?d=identicon&s=25 Daniel S. (dasch)
on 2005-12-03 17:04
(Received via mailing list)
Daniel Schierbeck wrote:
>> Cheers,
>   end
> Daniel
Oooops, #append_features is private, so it should be

   M.send :append_features, self


Cheers,
Daniel
30804046d28e30e9492f5309a57a6c31?d=identicon&s=25 Daniel S. (dasch)
on 2005-12-03 18:13
(Received via mailing list)
ts wrote:
>    def self.included(klass)
>
> module M
> end
> Guy Decoux
Um, yeah. `append_features' does the actual work (appending the methods
of a module to a class/module), `include' just calls `append_features'
and then `included'.

   class Module
     def include(*mods)
       mods.each do |mod|
         mod.append_features(self)
         mod.included(self)
       end
     end
   end


Cheers,
Daniel
decoux (Guest)
on 2005-12-03 18:21
(Received via mailing list)
>>>>> "D" == Daniel Schierbeck <daniel.schierbeck@gmail.com> writes:

D> Um, yeah. `append_features' does the actual work (appending the
methods
D> of a module to a class/module), `include' just calls
`append_features'
D> and then `included'.

 yes, and this is why you must call super in #append_features (if you
 redefine it) otherwise ruby don't include the module.

Guy Decoux
30804046d28e30e9492f5309a57a6c31?d=identicon&s=25 Daniel S. (dasch)
on 2005-12-03 19:38
(Received via mailing list)
ts wrote:
>>>>>> "D" == Daniel Schierbeck <daniel.schierbeck@gmail.com> writes:
>
> D> Um, yeah. `append_features' does the actual work (appending the methods
> D> of a module to a class/module), `include' just calls `append_features'
> D> and then `included'.
>
>  yes, and this is why you must call super in #append_features (if you
>  redefine it) otherwise ruby don't include the module.
>
> Guy Decoux

Yup.
transfire (Guest)
on 2005-12-03 22:14
(Received via mailing list)
Daniel Schierbeck wrote:
>        end
>      end
>    end

It does? Looking at the C code it seems a lot more complicated then
that.

T.
This topic is locked and can not be replied to.