Support subtypes in type based pattern matching
beezee opened this issue · comments
It'd be nice to match subclasses of defined types, eg:
class MyInt < Integer end
class Something
defn(:accept_int, Integer) { |i| i }
end
Something.new.accept_int(MyInt(3))
I was surprised that this wasn't the default, but then the only strongly typed language I have experience with is Scala, so I'm not sure whether there are cases where this is wholly unsupported or requires a modifier.
Would be a simple change to MethodSignature.arg_is_type_of_param? to use kind_of? instead of is_a? https://github.com/jdantonio/functional-ruby/blob/master/lib/functional/method_signature.rb#L51
Let me know if this is a change you'd accept and I will put together a PR for this as well.
Nevermind I was doing something dumb, this is exactly how it works already.