On Fri, Oct 28, 2011 at 3:40 PM, Intransition <transfire / gmail.com> wrote:
> Can it be done?
>
> E.g.
>
> =A0o =3D BasicObject.new
> =A0o.extend Enumerable

Funnily enough I stumbled across the very same issue a few days ago.
The reason you can't #extend is

irb(main):001:0> Object.instance_method :extend
=3D> #<UnboundMethod: Object(Kernel)#extend>

And since

irb(main):002:0> Object < Kernel
=3D> true
irb(main):003:0> BasicObject < Kernel
=3D> nil

you cannot bind method extend to an instance of BasicObject:

irb(main):019:0> Object.instance_method(:extend).bind(BasicObject.new)
TypeError: bind argument must be an instance of Object
        from (irb):19:in `bind'
        from (irb):19
        from /opt/bin/irb19:12:in `<main>'


There is just one way I am aware of:

irb(main):010:0> class X < BasicObject
irb(main):011:1> def initialize
irb(main):012:2> class<<self; include ::Enumerable; end
irb(main):013:2> end
irb(main):014:1> end
=3D> nil
irb(main):015:0> x=3DX.new
(Object doesn't support #inspect)
=3D>
irb(main):016:0> Enumerable =3D=3D=3D x
=3D> true

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/