Created
October 18, 2025 00:43
-
-
Save Sija/7b74e54e01585d1665f8e0c2a043282b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class Magic(T) | |
| getter object : T | |
| def initialize(@object : T) forall T | |
| end | |
| forward_missing_to @object | |
| def ~ : T | |
| object | |
| end | |
| def if(&) : self | Magic(Nil) | |
| yield(self) ? self : Magic.new(nil) | |
| end | |
| def if!(&) : T? | |
| object if yield self | |
| end | |
| end | |
| class Object | |
| def __ : Magic | |
| Magic.new(self) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment