Created
February 21, 2020 00:53
-
-
Save rantler/e4cc6f1f537ddf16cdea4f631cc6ee3c to your computer and use it in GitHub Desktop.
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
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