Transparently use native ruby types


A ruby class is already a type. However, to specify it within a dry-types declaration we must wrap it in Types.Instance(). For example:

# => NoMethodError: undefined method `call_unsafe' for Object:Class
# => ["a"]

Would it be too difficult to transparently swallow ruby native types? And what are your thoughts about it?


We must wrap it so that it’s not ambiguous. Inferring type from a core primitive could be tricky and it could even lead to subtle bugs; furthermore, I would not like to see code like this:

attribute :foo, Float
attribute :bar, Types::Integer.constrained(gt: 0)

I understand where you’re coming from with this, but if it really bothers you, it should be trivial to add your own helper method that would cover your specific use cases.


Yep, your point is very fair. I had contradictory feelings with it anyway. Thanks!

1 Like