ãã¹ãã¨ãã§ãããããªãã¨æããã©ããããªãã ããªããã¨ã« gem ã¨ã使ããããªãã®ã§ãç°¡åã«æ¸ããæ¹æ³ããããã¦ãã class Foo def hello puts "Hello" end end ã¿ãããªã¯ã©ã¹ããã£ãã¨ãã¦ãhello ã¡ã½ãããä¸æçã«ä¸æ¸ãããã (ããã¦æ»ããã) ã¨ã ãããªãã¸ã§ã¯ãã®ã¡ã½ããã ããä¸æ¸ã ãã㯠singleton class ã使ã£ããããã§ããã®ã§ãããã foo = Foo.new orig = foo.method(:hello) # å ã®ã¡ã½ãããå¼ã³ããã¨ãã ãå¿ è¦ foo.define_singleton_method(:hello) do puts "before hello" orig.call puts "after hello" end foo.hello #=> # before hello # Hello #
{{#tags}}- {{label}}
{{/tags}}