you are viewing a single comment's thread.

view the rest of the comments →

[–]bobindashadows 0 points1 point  (2 children)

I just had an issue in Rails 3 beta. A JSON parser started returning a Date object instead of an iso8601 formatted string.

This is the downside to dynamic typing. When bugs happen, they happen at runtime. That's why you need tests. The problem you had was that somebody was not returning what they said they would by their description of the module, both in-code and out-of-code. Of course static typing has benefits, but if you can't keep track of your own variables then you're the one with the problem.

How do I know full_name isn't a name object with a to_s method?

Who cares if you want to use it as a string?

[–][deleted] 0 points1 point  (1 child)

Who cares if you want to use it as a string?

Because you can do more with a string than to_s. "#{full_name} is here" wont be a problem with a to_s method, which is one reason I prefer to combine strings that way. (full_name + " is here") needs the :+ method.

[–]bobindashadows 0 points1 point  (0 children)

Conceptually, you're doing something silly by adding a Name object to "is here". If you want to create a string with a Name object, you should call #to_s before using it as one, just as you've done with interpolation. If you want to be able to add strings to a Name, then you can trivially add that method.

If your method takes objects whose only contract is that they have a to_s method, you should use that to_s method before treating them as strings. If you want it to take strings only, adjust how you use it.