Skip to content

Instantly share code, notes, and snippets.

@rantler
Created February 21, 2020 00:53
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 rantler/e4cc6f1f537ddf16cdea4f631cc6ee3c to your computer and use it in GitHub Desktop.
Save rantler/e4cc6f1f537ddf16cdea4f631cc6ee3c to your computer and use it in GitHub Desktop.
class Foo
def meth(a:, b:, c:)
method(__method__).parameters.map(&:last).each do |var|
instance_variable_set("@#{var}", binding.local_variable_get(var))
end
end
def inspect
puts "@a = #{@a}"
puts "@b = #{@b}"
puts "@c = #{@c}"
end
end
inst = Foo.new
inst.meth(a: 'a', b: 'b', c: 'c')
inst.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment