Skip to content

Instantly share code, notes, and snippets.

@pinzolo
Created October 15, 2012 12:45
Show Gist options
  • Save pinzolo/3892267 to your computer and use it in GitHub Desktop.
Save pinzolo/3892267 to your computer and use it in GitHub Desktop.
define_methodで可変長引数のメソッドを定義する
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
# => []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment