|
|
|
|
|
by Lammy
1244 days ago
|
|
> Some more examples, in Ruby, instead of calling `implement Module`, it uses `include Module` . I do think include is not as clear as implement. Agreed, though I do think the `include` naming might just be a relic from a time before `prepend` and `extend` also existed in Ruby. I find it a lot more intuitive when I remember it as `append`ing to the ancestors, and the language even sort of calls it that internally with the naming mismatch between `include` and `append_features`: https://ruby-doc.org/3.2.0/Module.html#method-i-include Then one can see that's exactly what it does to a Module's ancestor chain: irb(main):001:0> RUBY_VERSION => "3.2.0"
irb(main):002:0> lol = ::Module::new => #<Module:0x00007f2969821740>
irb(main):003:0> lol.ancestors => [#<Module:0x00007f2969821740>]
irb(main):004:0> lol.singleton_class.ancestors => [#<Class:#<Module:0x00007f2969821740>>, Module, Object, PP::ObjectMixin, Kernel, BasicObject]
irb(main):005:0> rofl = ::Module::new => #<Module:0x00007f296982dfe0>
irb(main):006:0> lmao = ::Module::new => #<Module:0x00007f296982fd40>
irb(main):007:0> omg = ::Module::new => #<Module:0x00007f2969822a00>
irb(main):008:0> lol.include(rofl) => #<Module:0x00007f2969821740>
irb(main):009:0> lol.prepend(lmao) => #<Module:0x00007f2969821740>
irb(main):010:0> lol.extend(omg) => #<Module:0x00007f2969821740>
irb(main):011:0> lol.ancestors => [#<Module:0x00007f296982fd40>, #<Module:0x00007f2969821740>, #<Module:0x00007f296982dfe0>]
irb(main):012:0> lol.singleton_class.ancestors => [#<Class:#<Module:0x00007f2969821740>>, #<Module:0x00007f2969822a00>, Module, Object, PP::ObjectMixin, Kernel, BasicObject]
|
|