2 ms·
Not Ruby, but Rails. And there, it is handled by a clear and dedicated layer: ActiveModel::Type::Boolean.new.cast(value) The only thing you can complain about
by berkes 6y ago
Not Ruby, but Rails.
And there, it is handled by a clear and dedicated layer: ActiveModel::Type::Boolean.new.cast(value)
The only thing you can complain about is that Rails loves implicit magic, which will call this layer for you. Without you needing to set it up, or call it yourself. Many people love this about Rails. (I prefer explicitness over magic.)
- rorykoehler 6y agoOnce you learn rails well enough it all becomes explicit because you can simply read the source code.
- berkes 6y agoExplicit, for me, means that I determine in the model the `published_at` is a DateTime. Not merely in the DB, and never magically derived from the name (_at=datetime, _on=date). But explicitely defined. E.g. `attribute(:published_at, DateTime, default: ->{DateTime.now})` Rails does not do this entirely "magic", though: it derives it from the database. And true: you can follow the logic along: the magic can be researched easily. But still: I really prefer a system in which I write all that boilerplace (my IDE/vim can do this for me really well) instead of relying on convention, heuristics and magic.