1.9.3-p194 :012 > b=[1,2,3];b.instance_variable_set :@internal, "rrr";
b.define_singleton_method :xx do; @internal; end
=> #<Proc:0x000000020f3d20@(irb):12 (lambda)>
1.9.3-p194 :013 > b
=> [1, 2, 3]
1.9.3-p194 :014 > b.xx
=> "rrr"
1.9.3-p194 :015 > b.define_singleton_method :"xx=(val)" do; @internal=val; end
=> #<Proc:0x0000000254aec8@(irb):15 (lambda)>
1.9.3-p194 :017 > b.xx="yy"
NoMethodError: undefined method `xx=' for [1, 2, 3]:Array
from (irb):17
from /home/sir/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'
我想要编写器作为实例变量,但它不起作用。我究竟做错了什么?