Damian,
I think we are saying the same thing: using the object's own methods
(to_i, to_a, to_f, etc.) to typecast/coerce is absolutely the right
thing to do.  Unfortunately, Rails currently goes beyond that level of
coercion and Josh's original proposal on this post was to go even
further to coerce booleans using external logic.  It's the use of
external logic that I characterized as "guessing."

-Chris

On Aug 20, 6:47 pm, "Damian Janowski" <[EMAIL PROTECTED]>
wrote:
> On Wed, Aug 20, 2008 at 12:34 PM, Chris Cruft <[EMAIL PROTECTED]> wrote:
> > Honestly, having the persistence layer guess at what is "intended" to
> > be stored seems like a losing proposition.  What's next?  Guessing
> > that for a boolean field "Nein" means false and "Oui" means true and
> > that for an integer field that "Two" means 2 and "a lot" means 3?
>
> Quick thought: I don't think calling #to_i is guessing. I see it as "I
> expect an integer, please provide me with whatever you can to satisfy
> that". I think most Ruby APIs are like that. So I always call #to_s or
> #to_i in methods that expect such types.
>
> Just like AR will call #to_i on #find when passed a string. It's ok,
> and it lets you do some more magic and makes your code look a lot
> better.
>
> Just my $0.2
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to