覆盖is_a的正确方法是什么?和kind_of?

时间:2011-02-04 04:36:51

标签: ruby

ruby​​ 1.8.7(2010-12-23 patchlevel 330)[i686-darwin10.5.0]

我错过了什么吗?

module Mixin
  def is_a?(o)
    return false if o == Hash
    super
  end
  alias_method :kind_of?, :is_a?
end

class Doc < Hash
  include Mixin
end

puts Doc.new().is_a?(Doc) # => true
puts Doc.new().kind_of?(Doc) # => super: no superclass method `is_a?'

预期:

puts Doc.new().is_a?(Doc) # => true
puts Doc.new().kind_of?(Doc) # => true
puts Doc.new().is_a?(Hash) # => false
puts Doc.new().kind_of?(Hash) # => false

rubinius和ruby 1.9.2p136

上的一切都很酷

1 个答案:

答案 0 :(得分:2)

感谢大家。这是1.8.7 http://redmine.ruby-lang.org/issues/show/734

中的错误