Quick actions

cmd+k|ctrl+k

Navigation

Languages

implement instance_exec

Snippet info

Language

Ruby

Visibility

public

Author

hyrious

Created

2019-02-17T08:02:53Z

Updated

2019-02-19T01:45:34Z

class A
  def initialize *a, &b
    return if !b
    m = singleton_class.class_eval do
      define_method :cloaker_, &b
      meth = instance_method :cloaker_
      remove_method :cloaker_
      meth
    end
    m.bind(self).call(*a)
  end
  def miao
    p 42
  end
end

module B
  y = 24 #<- y is in B
  A.new 33 do |z|
    miao
    p y, z
  end
end
INFO