| TL;DR I totally agree. This can be done with Crystal and Lucky but I wanted to keep the example simple. I totally agree with your sentiment and you have a lot of great points. This post was not meant to get too deep into things right off the bat, so it left off a lot of this stuff. In this case the phone number always has a country code with +1 because we have a validation that ensures it won't make it into the database without it. We also only accept US country codes in the validation. I get your point though that just having a `String` doesn't really guarantee that those validations took place, luckily, LuckyRecord has the idea of custom types that can define their own casting and validation behavior. So we could have done this: ```
field phone : UnitedStatesPhoneNumber?
``` And it would validate that the string param is a valid US number before saving. It would also do that for queries and you could add whatever other type specific methods you want to it. so you could do ```
def formatted_fax_number
phone.try { |number| number.without_country_code }
end
``` But like I said, I think this is fitting for a whole separate post, rather than an intro style post :D |
I will go more into depth about leveraging the type system with Lucky for even better data modeling in one of the Lucky guides