Created
March 26, 2022 15:54
-
-
Save okuramasafumi/cb796f17a123474f766d776be04db02b to your computer and use it in GitHub Desktop.
Ice feature from zinit in Ruby
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
module Kernel | |
def ice(key, value, on: Object) | |
if on.instance_methods.include?(key.to_sym) | |
prev = on.instance_method(key) | |
on.define_method key do | |
on.remove_method key | |
on.define_method(key, prev) | |
return value | |
end | |
else | |
on.define_method key do | |
on.remove_method key | |
return value | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment