Skip to content

Instantly share code, notes, and snippets.

@okuramasafumi
Created March 26, 2022 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okuramasafumi/cb796f17a123474f766d776be04db02b to your computer and use it in GitHub Desktop.
Save okuramasafumi/cb796f17a123474f766d776be04db02b to your computer and use it in GitHub Desktop.
Ice feature from zinit in Ruby
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