rubydefine_methodã§ããã©ã«ãå¼æ°ã使ããªããï¼ã¨æã£ã¦èª¿ã¹ã¦ãããè¦ã¤ãã¾ããã Ruby1.9以ä¸ãããªãã¨ãã¡ã§ãããno title ã®2çªç®ã®åçã«ããããã«lambdaãªãã©ã«ã使ãã°åºæ¥ã¾ããã class Hoge def create_greet self.class.class_eval do define_method("greet", ->(message = 'Hello', option = ' World!') { puts "#{message} #{option}" }) end end end hoge = Hoge.new hoge.create_greet hoge.greet hoge.greet('Goodbye') hoge.greet('ããã«ã¡ã¯', 'ä¸ç') æåã¯ãªãã ããï¼ã¨æã£ãlambdaãªãã©ã«ã ãã©ããªãã
{{#tags}}- {{label}}
{{/tags}}