Skip to content

Instantly share code, notes, and snippets.

@PavloConan
Created January 28, 2018 13:12
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 PavloConan/7602ebec67830a5e44126430797c8b11 to your computer and use it in GitHub Desktop.
Save PavloConan/7602ebec67830a5e44126430797c8b11 to your computer and use it in GitHub Desktop.
class MyClass
def initialize(**args)
args.each do |k, v|
instance_variable_set("@#{k}", v)
define_singleton_method(k) do
instance_variable_get(:"@#{k}")
end
define_singleton_method("#{k}=") do |v|
instance_variable_set("@#{k}", v)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment