diff --git a/hobo/hobofields/lib/hobo_fields.rb b/hobo/hobofields/lib/hobo_fields.rb index 5d411d9..e5346de 100644 --- a/hobo/hobofields/lib/hobo_fields.rb +++ b/hobo/hobofields/lib/hobo_fields.rb @@ -68,14 +68,24 @@ module HoboFields end - def can_wrap?(type, val) - col_type = type::COLUMN_TYPE - return false if val.blank? && (col_type == :integer || col_type == :float || col_type == :decimal) - klass = Object.instance_method(:class).bind(val).call # Make sure we get the *real* class - init_method = type.instance_method(:initialize) - [-1,1].include?(init_method.arity) && - init_method.owner != Object.instance_method(:initialize).owner && - !@never_wrap_types.any? { |c| klass <= c } + if Object.instance_method(:initialize).arity!=0 + def can_wrap?(type, val) + col_type = type::COLUMN_TYPE + return false if val.blank? && (col_type == :integer || col_type == :float || col_type == :decimal) + klass = Object.instance_method(:class).bind(val).call # Make sure we get the *real* class + init_method = type.instance_method(:initialize) + [-1,1].include?(init_method.arity) && + init_method.object_id != Object.instance_method(:initialize).object_id && + !@never_wrap_types.any? { |c| klass <= c } + end + else + def can_wrap?(type, val) + col_type = type::COLUMN_TYPE + return false if val.blank? && (col_type == :integer || col_type == :float || col_type == :decimal) + klass = Object.instance_method(:class).bind(val).call # Make sure we get the *real* class + init_method = type.instance_method(:initialize) + [-1,1].include?(init_method.arity) && !@never_wrap_types.any? { |c| klass <= c } + end end