Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add #respond_to? tests and fix behaviour
The previous implementation was completely wrong, which I didn’t realise until I tried to add tests around it. This commit adds the tests and simultaneously fixes the code to actually work. A generic implementation of #respond_to_missing? can’t work[1] because answering the question requires knowledge of #and_then’s control flow; for example, Optional only sends the message to the underlying value if it’s not nil, so #respond_to_missing? should return true if the value is nil and ask if it responds to the message otherwise. We have no way of knowing what #and_then’s control flow will look like in general, so we just have to lovingly recreate it in #respond_to_missing? for each monad, which is annoying but necessary. [1] In fact, it *could* work by simply sending the message and reporting whether a NameError is raised, but that would defeat the entire purpose of #respond_to?, namely to tell you whether a message can be sent without actually sending it.
- Loading branch information
Showing
7 changed files
with
76 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters