instance_eval & instance_exec
class A def initialize(x,y) @x = x @y = y endend</pre></code> obj = A.new(‘rays’, ‘rashmi’)obj.instanceeval{puts “Hello #{@x} #{@y}”} => Hello rays rashmi</code></pre>obj.instanceexec(“Hello”){|arg| puts “#{arg} #{@x} #{@y} “}=> Hello rays rashmi</code></pre> …
Continuar lendo