如何用 JRuby 覆盖 ActiveRecord::Type::Boolean

How to override ActiveRecord::Type::Boolean with JRuby

我正在尝试将活动记录 class 覆盖为 return true/false 而不是 1/0。该示例对 Ruby 非常有效,但对 JRuby 无效。

module ActiveRecord::Type
  class Boolean    
    def type_cast(value, column = nil)
      ActiveRecord::ConnectionAdapters::Column::FALSE_VALUES.include?(value) ? false : true
    end
  end
end

感谢提前。

运行 Ruby 2.1.x 适用于 JRuby 1.7.x/Ruby 1.9.x。 谢谢@ThomasHaratyk