From: "phluid61 (Matthew Kerwin)" Date: 2013-03-08T16:27:18+09:00 Subject: [ruby-core:53220] [ruby-trunk - Feature #8046] allow Object#extend to take a block Issue #8046 has been updated by phluid61 (Matthew Kerwin). david_macmahon (David MacMahon) wrote: > Which raises another question: what would be the order of extending if > #extend is passed one or more modules *and* given a block? IOW, should > the passed in module(s) be included first thereby giving the block the > opportunity to override them or vice versa (or should this be explicitly > disallowed)? I guess I'd favor the first way (include module(s) first, > then block can override). That's the order Facets uses: https://github.com/rubyworks/facets/blob/master/lib/core/facets/kernel/extend.rb > On the original question I tend to agree with @phluid61 that it would be > preferable to avoid inserting an anonymous Module in the > singleton_class's ancestors. Would having the anonymous module provide > any advantage over not having it? My reasoning against was that on calling it a second time, there would be a second anonymous module, and so on. > P.S. Why "singleton_class.send(:include, Module.new(&bk))" instead of > just "singleton_class.include(Module.new(&bk))"? Are these somehow not > equivalent? #include is private, so can't be called directly from outside the singleton_class object. ---------------------------------------- Feature #8046: allow Object#extend to take a block https://bugs.ruby-lang.org/issues/8046#change-37382 Author: phluid61 (Matthew Kerwin) Status: Open Priority: Normal Assignee: Category: Target version: next minor =begin In #8038 david_macmahon proposed: How about allowing Object#extend to take a block that would be executed with the context such that methods defined therein would become singleton methods of the object receiving #extend? For example: foo = Object.new foo.extend do def bar # ... end def baz # ... end end =end -- http://bugs.ruby-lang.org/