Return value based on parameter type : kind_of « Reflection « Ruby






Return value based on parameter type


def coerce(other)
  if other.kind_of?(Float)
    return other, self.to_f
  elsif other.kind_of?(Integer)
    return other, self.to_i
  else
    super
  end
end

 








Related examples in the same category

1.determine our object's class and its unique objectID and test its relationship to other classes.
2.use Object's is_a? or kind_of? methods (they are synonyms)