gogotanaka / Rubype

:dromedary_camel: Super simple, clean. Contracts for Ruby
http://gogotanaka.github.io/rubype.github.io/
377 stars 14 forks source link

Optional #4

Open gogotanaka opened 9 years ago

gogotanaka commented 9 years ago

like that?

typesig :method, [Integer] => (String | NilClass)
grempe commented 8 years ago

This would be very useful. I think its pretty common to return one type or the other depending on the outcome of the method. e.g. Return a Hash on success and nil on failure. There is currently no way to typesig this type of method without using the blanket Any which may let through other types that are unwanted.

The input args should also be able to be specified as one | another:

# allow an Integer OR a String for the first arg, a String for the second, and return a String OR nil
typesig :method, [Integer | String, String] => (String | NilClass)