Project

General

Profile

Actions

Feature #8465

closed

Proc set_binding

Added by beanstalksurf (Jacob Burkhart) almost 11 years ago. Updated over 10 years ago.

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

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 puts_a_foo
Proc.new do |arg|
puts self.foo(arg)
end
end
end

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

foo_putter = BarFoo.new.puts_a_foo

foo_putter.call("blah")

bar blah

FooFoo.new.instance_eval(&foo_putter)
#foo #FooFoo:0x007ff0b903f9b0

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

bar blah

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

foo blah

#I expect...
foo_putter.set_binding(FooFoo.new.foo_foo_proc.binding)
foo_putter.call("blah")
#to output:

foo blah

=end

Updated by beanstalksurf (Jacob Burkhart) almost 11 years ago

Oops, I meant that last line to say:

#I expect...
foo_putter.set_binding(FooFoo.new.foo_foo_proc.binding)
foo_putter.call("blah")
#to output:

foo blah

Updated by nobu (Nobuyoshi Nakada) almost 11 years ago

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

=begin
Try:

FooFoo.new.instance_exec('blah', &foo_putter)
=end

Updated by ko1 (Koichi Sasada) over 10 years ago

  • Status changed from Feedback to Rejected

Difficult to implement.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0