Sha256: 897a3b51cace61385f51a851cb9a08de85c6d5c87df437b67531b02ba264415c
Contents?: true
Size: 536 Bytes
Versions: 1
Compression:
Stored size: 536 Bytes
Contents
class Object unless instance_methods.include? 'instance_exec' def instance_exec *a, &b m = "__instance_exec_#{ Thread.current.object_id.abs }__" singleton_class{ define_method m, &b } send m, *a ensure singleton_class{ undef_method m } rescue nil end end unless instance_methods.include? 'singleton_class' def singleton_class &b sc = class << self; self; end sc.module_eval &b if b sc end end end a = [] a.instance_exec 42 do |elem| push elem end p a
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fsm-0.0.0 | instance_exec.rb |