Feature #8465

Proc set_binding

Added by Jacob Burkhart 11 months ago. Updated 9 months ago.

[ruby-core:55210]
Status:Rejected
Priority:Normal
Assignee:-
Category:-
Target version:-

Description

=begin
(({instance_eval})) is a solution to evaluate a proc in the binding of another object

but it is not a solution for a (({Proc})) that takes arguments

I propose that in order to suppor this use-case we need (({Proc#set_binding}))

Example:

class BarFoo
def foo(arg)
"bar #{arg}"
end
def putsafoo
Proc.new do |arg|
puts self.foo(arg)
end
end
end

class FooFoo
def foo(arg)
"foo #{arg}"
end
def foofooproc
Proc.new{}
end
end

fooputter = BarFoo.new.putsa_foo

foo_putter.call("blah")
# bar blah

FooFoo.new.instanceeval(&fooputter)
#foo #FooFoo:0x007ff0b903f9b0

foo_putter.binding.eval("puts self.foo('blah')")
# bar blah

FooFoo.new.foofooproc.binding.eval("puts self.foo('blah')")
# foo blah

#I expect...
fooputter.setbinding(FooFoo.new.foofooproc.binding)
foo_putter.call("blah")
#to output:
# foo blah
=end

History

#1 Updated by Jacob Burkhart 11 months ago

Oops, I meant that last line to say:

#I expect...
fooputter.setbinding(FooFoo.new.foofooproc.binding)
foo_putter.call("blah")
#to output:

foo blah

#2 Updated by Nobuyoshi Nakada 11 months ago

  • Description updated (diff)
  • Status changed from Open to Feedback

=begin
Try:

FooFoo.new.instanceexec('blah', &fooputter)
=end

#3 Updated by Koichi Sasada 9 months ago

  • Status changed from Feedback to Rejected

Difficult to implement.

Also available in: Atom PDF