Last active
February 17, 2023 00:02
-
-
Save noelrappin/9b2dfcd84bf3d5082f69bfc8189907f0 to your computer and use it in GitHub Desktop.
Sigilize
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 Module | |
def sigilize(method_name) | |
define_method("#{method_name}?") do |*args, **kwargs| | |
!!method_name(*args, **kwargs) | |
end | |
define_method("#{method_name}!") do |*args, **kwargs| | |
result = method_name(*args, **kwargs) | |
raise StandardError unless result | |
result | |
end | |
end | |
end | |
## Usage | |
class Process | |
def status | |
#whatever | |
end | |
sigilize(:status) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment