Project

General

Profile

Actions

Backport #2161

closed

Kernel.eval ignores binding in 1.9

Added by awieland (Aaron Wieland) over 14 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
[ruby-core:25866]

Description

=begin
Kernel.eval no longer evaluates its string in the context of the binding passed to it.

In an irb session in 1.8.6:

irb(main):001:0> eval 'self'
=> main
irb(main):002:0> obj = Object.new
=> #Object:0x12aaf20
irb(main):003:0> eval 'self', obj.send(:binding)
=> #Object:0x12aaf20

In 1.9.1 (also tested in the latest nightly build for 1.9.2):

irb(main):001:0> obj = Object.new
=> #Object:0x5210f8
irb(main):002:0> eval 'self', obj.send(:binding)
=> main

I can't help but feel I'm missing something, because a bug of this magnitude should have been identified and fixed by now (it breaks a lot of code that uses ERb).
=end

Actions #1

Updated by wanabe (_ wanabe) over 14 years ago

=begin
It seems that Kernel#eval works fine.

$ ./ruby -ve 'class Foo;def foo;binding;end;end;eval "p self", Foo.new.foo'
ruby 1.9.2dev (2009-10-02 trunk 25185) [i386-mingw32]
#Foo:0xb23f80

I guess obj.send(:binding)' is same as binding' in 1.9.
And it is undefined behavior, because Kernel#binding is a private method.
How about Object#instance_eval instead of it?
=end

Actions #2

Updated by naruse (Yui NARUSE) over 14 years ago

  • Status changed from Open to Feedback

=begin

=end

Actions #3

Updated by mame (Yusuke Endoh) almost 14 years ago

=begin
Hi,

Rdoc of Kernel#binding says:

Returns a +Binding+ object, describing the variable and
method bindings at the point of call.

In this case, "the point of call" is top level.
So I think 1.9 is correct.

I don't know it is 1.8's bug or spec change since 1.9.
So I move this ticket to 1.8 subproject.

As wanabe said, you can use instance_eval if you want 1.8's
current behavior:

eval "self", obj.instance_eval { binding }

--
Yusuke Endoh
=end

Actions #4

Updated by jeremyevans0 (Jeremy Evans) over 4 years ago

  • Tracker changed from Bug to Backport
  • Project changed from Ruby 1.8 to Backport187
  • Description updated (diff)
  • Status changed from Feedback to Closed
  • ruby -v deleted (1.9.1p243 (2009-07-16 revision 24175) [i386-darwin9.8.0])
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0