例 def foo(obj, val) (class << obj self end).module_eval { define_method(:bar) { val } } end a = Object.new foo(a,3) p a.bar