morganwildermuth / LPCodingChallenge

0 stars 0 forks source link

explanation of String#is_a_number? #4

Closed vinbarnes closed 10 years ago

vinbarnes commented 10 years ago

Can you explain why you chose the logic behind this method? https://github.com/morganwildermuth/LPCodingChallenge/blob/master/string_class_methods.rb#L10-L12

def is_a_number?
  self == "0" || self.to_f != 0.0
end
morganwildermuth commented 10 years ago

Honestly, it was a poor choice. At some point, it seemed plausible that someone might want to pull data out in float form, including data that was initially a string which would have a 0.0 value in float form. This method was initially created with that problem fresh in my mind; this seemed clearer than a regex solution. I've updated it to use regex.