Current Path : /usr/local/share/ri/1.8/system/Module/ |
FreeBSD hs32.drive.ne.jp 9.1-RELEASE FreeBSD 9.1-RELEASE #1: Wed Jan 14 12:18:08 JST 2015 root@hs32.drive.ne.jp:/sys/amd64/compile/hs32 amd64 |
Current File : //usr/local/share/ri/1.8/system/Module/define_method-i.yaml |
--- !ruby/object:RI::MethodDescription aliases: [] block_params: comment: - !ruby/struct:SM::Flow::P body: Defines an instance method in the receiver. The <em>method</em> parameter can be a <tt>Proc</tt> or <tt>Method</tt> object. If a block is specified, it is used as the method body. This block is evaluated using <tt>instance_eval</tt>, a point that is tricky to demonstrate because <tt>define_method</tt> is private. (This is why we resort to the <tt>send</tt> hack in this example.) - !ruby/struct:SM::Flow::VERB body: " class A\n def fred\n puts "In Fred"\n end\n def create_method(name, &block)\n self.class.send(:define_method, name, &block)\n end\n define_method(:wilma) { puts "Charge it!" }\n end\n class B < A\n define_method(:barney, instance_method(:fred))\n end\n a = B.new\n a.barney\n a.wilma\n a.create_method(:betty) { p self }\n a.betty\n" - !ruby/struct:SM::Flow::P body: <em>produces:</em> - !ruby/struct:SM::Flow::VERB body: " In Fred\n Charge it!\n #<B:0x401b39e8>\n" full_name: Module#define_method is_singleton: false name: define_method params: | define_method(symbol, method) => new_method define_method(symbol) { block } => proc visibility: public