-
-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add respond_to? predicate #55
Conversation
This is not a problem. This module is a placeholder for predicates, the actual API are predicates themselves, not the module that contains them. |
@solnic It is a problem for code that performs introspection on the running program which has |
@dgutov wdym? it does not affect anything outside of dry-logic. |
dry-logic are not meant to be introspected anyway, not with |
@solnic It breaks application code like: ObjectSpace.each_object(Module).select { |m| m.respond_to?(:dry) } I have a plucky little code assistance tool which (very roughly speaking) uses this approach. |
@dgutov oh boy 😭 well, please report an issue then. This is something we can change in 2.0.0. |
For the record, changing it may affect performance since method dispatching is optimized in ruby as well as in dry-logic |
@flash-gordon I reckon we can live with that, I suspect it's not a commonly used predicate |
@solnic ah, no I thought of something more fundamental like changing the way we group predicates, e.g. having them in a hash rather than a module |
@flash-gordon ah no, we should just rename it to something like...I dunno, |
@dgutov a work around would be respond_to = Class.instance_method(:respond_to?)
ObjectSpace.each_object(Module).select { |m| respond_to.bind_call(m, :dry) }
|
@flash-gordon This is a decent idea, but it enters murky waters. And the particular line where I'm getting an error because of this addition to |
@solnic Reported. ;) |
@dgutov thanks! I added it to |
This is part of a feature for
dry-types
about being able to define a type by a contract of implemented methods in the value.Calling the predicate method
respond_to?
has the undesired side effect of obfuscatingObject#respond_to?
inDry::Logic::Predicates
. An alternative would be to name itresponds_to?
, but it would be less intuitive for users who would find more natural to have the predicate named like the method. Another solution would be to decouple predicate names fromDry::Logic::Predicates
method names. What do you think?Resources