Likewise 
$ cat bar.rb
#!/usr/lib/fullstaq-ruby/versions/3.0-jemalloc/bin/ruby
require 'rensei'
$bindings = {}
def meth
x = rand
end
p meth, $bindings
puts
eval <<~END
def meth
begin
#{
Rensei.unparse(
RubyVM::AbstractSyntaxTree.of(
method(:meth)
)
)
}
ensure
$bindings[[self, __method__]] = binding
end
end
END
p meth, $bindings
p $bindings[[self, :meth]].local_variable_get(:x)
p $bindings[[self, :meth]].local_variable_get(:x)
p $bindings[[self, :meth]].local_variable_get(:x)
puts
p meth, $bindings
p $bindings[[self, :meth]].local_variable_get(:x)
p $bindings[[self, :meth]].local_variable_get(:x)
p $bindings[[self, :meth]].local_variable_get(:x)
puts
module Mod
def self.meth
y = rand
end
end
p Mod.meth, $bindings
puts
eval <<~END
def Mod.meth
begin
#{
Rensei.unparse(
RubyVM::AbstractSyntaxTree.of(
Mod.method(:meth)
)
)
}
ensure
$bindings[[self, __method__]] = binding
end
end
END
p Mod.meth, $bindings
p $bindings[[Mod, :meth]].local_variable_get(:y)
p $bindings[[Mod, :meth]].local_variable_get(:y)
p $bindings[[Mod, :meth]].local_variable_get(:y)
puts
p Mod.meth, $bindings
p $bindings[[Mod, :meth]].local_variable_get(:y)
p $bindings[[Mod, :meth]].local_variable_get(:y)
p $bindings[[Mod, :meth]].local_variable_get(:y)
puts
$ ./bar.rb
0.9643116068264609
{}
0.02842814636779123
{[main, :meth]=>#<Binding:0x00007bd237e84e70>}
0.02842814636779123
0.02842814636779123
0.02842814636779123
0.6696453472343303
{[main, :meth]=>#<Binding:0x00007bd237e84830>}
0.6696453472343303
0.6696453472343303
0.6696453472343303
0.9617944924642181
{[main, :meth]=>#<Binding:0x00007bd237e84830>}
0.6628385990769972
{[main, :meth]=>#<Binding:0x00007bd237e84830>, [Mod,
:meth]=>#<Binding:0x00007bd237e93718>}
0.6628385990769972
0.6628385990769972
0.6628385990769972
0.3539253468317246
{[main, :meth]=>#<Binding:0x00007bd237e84830>, [Mod,
:meth]=>#<Binding:0x00007bd237e93150>}
0.3539253468317246
0.3539253468317246
0.3539253468317246
···
On 10/13/21, Die Optimisten <inform@die-optimisten.net> wrote:
as written in the beginning:
def mymeth
x=123
end
I don't want to bind every object manually.
Here's some more evil code that should never be used 