re: Flexible Ruby Value Object Initialisation VIEW POST

re: I don't see it as anything other than enabling 100% duck typing in the application. I'm ensuring that the application depends only on the ability t...

Negative. Proc clause in the case example I provided is depending only on the ability to respond.

Refinements are required to exist upfront: no 3rd party code that responds, but does not have a clue about them is accepted.

Hiding the type check in the module does not make it magically stop being a type check.

In itself, adding responses to a class clearly does not constitute type checking, it is simply "adding responses to a class".

So are you saying that needing to reference the module that adds the behaviour constitutes a form of type checking?

I am saying refinements depend on the type. 3 types in your example were explicitly checked and extended with some functionality. Other types, no matter whether they respond to / implement this functionality are rejected.

There is no way to supply my own type that mimics the functionality to the constructor, without monkey patching your code.

This is exactly how we do it in some Java, but this is not what I would call idiomatic ruby.

Refinements depend on the type

Everything in some way depends on the type, because the type defines the messages that can be received and the responses. That is not type checking, though, that is just code.

Other types, no matter whether they respond to / implement this functionality are rejected

If they respond to the correct message then they are not rejected by my ISBN class, because my ISBN class is not type checking. The refinements are just a way of adding the required responses that is safer than monkey patching, but ultimately they just define behaviour.

I would be keen on hearing other opinions, though.

code of conduct - report abuse