Tutorial by Examples

The instance_eval method is available on all objects. It evaluates code in the context of the receiver: object = Object.new object.instance_eval do @variable = :value end object.instance_variable_get :@variable # => :value instance_eval sets self to object for the duration of the co...
Many languages feature a with statement that allows programmers to omit the receiver of method calls. with can be easily emulated in Ruby using instance_eval: def with(object, &block) object.instance_eval &block end The with method can be used to seamlessly execute methods on object...

Page 1 of 1