The instance_eval method modifies self in its block, for example:
class D; end d = D.new d.instance_eval do puts self
If we define ourself method (or any other methods (except instance_eval) that accepts the block), when printing self, we will get "main", which is different from instance_eval method.eg:
[1].each do |e| puts self
How can I define a method (which takes a block) like instance_eval? Thanks in advance.
gaols
source share