2016-05-10から1日間の記事一覧
# クラスを動的に定義 A = Class.new # #1 # Aクラスのコンテクストで # private_methodであるdefine_methodを使用 A.class_eval{ define_method(:hoge){|a| puts a } } A.new.hoge("hoge") #=> "hoge" # #2 # Aクラスのコンテクストで # private_methodであ…
# クラスを動的に定義 A = Class.new # #1 # Aクラスのコンテクストで # private_methodであるdefine_methodを使用 A.class_eval{ define_method(:hoge){|a| puts a } } A.new.hoge("hoge") #=> "hoge" # #2 # Aクラスのコンテクストで # private_methodであ…