ポイントは7行目の *params と 9行目の *args かな。
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 Test | |
def self.method_missing(name, *args) | |
klass = class << self; self end | |
klass.class_eval do | |
define_method(name) do |*params| | |
p params | |
end | |
end | |
__send__(name, *args) | |
end | |
end | |
Test.hoge(1, 2, 3) | |
# => [1, 2, 3] | |
Test.hoge(1, 2) | |
# => [1, 2] | |
Test.hoge(1) | |
# => [1] | |
Test.hoge | |
# => [] |
0 件のコメント :
コメントを投稿