給定一個對象和一個模塊,如何檢查該對象是否已被模塊擴展?如何確定一個實例是否已被Ruby模塊擴展?
似乎沒有任何相應的擴展?方法
moirb(main):001:0> module Foobar
irb(main):002:1> end
=> nil
irb(main):003:0> o=Object.new
=> #<Object:0x000001010d1400>
irb(main):004:0> o.class.include? Foobar
=> false
irb(main):005:0> o.extend Foobar
=> #<Object:0x000001010d1400>
irb(main):006:0> o.class.include? Foobar
=> false
irb(main):007:0> o.class.included_modules
=> [PP::ObjectMixin, Kernel]
irb(main):016:0* o.methods.grep /extend/
=> [:extend]
irb(main):019:0> o.class.methods.grep /extend/
=> [:extend]
從來沒想過'include'和'include?'有同一個詞但之前有不同的含義。 –