Rubyã¯è¨èªä»æ§ã¨ãã¦ã¯overloadãæä¾ãã¦ãã¾ããããã©ã¤ãã©ãªã使ããã¨ã§overloadã§ãã¾ãã github.com 使ãæ¹ ã¾ãgemãã¤ã³ã¹ãã¼ã«ãã¾ãã $ gem install overloader ã¯ã©ã¹ã«Overloaderã¢ã¸ã¥ã¼ã«ãextendããoverloadã¡ã½ãããå¼ã³åºããã¨ã§overloadãè¡ãã¾ãã require 'overloader' class A extend Overloader overload do def foo() "no args" end def foo(x) "one arg" end def foo(x, y) "two args" end end end a = A.new p a.foo # => "no args" p a.foo(1) # => "one args" p a.foo(1, 2) # =>
{{#tags}}- {{label}}
{{/tags}}