rubinius/rubinius — pull request #1966 by yipdw (2012-10-21 03:37:22+00:00)
Title: Make BasicObject#instance_eval work with Strings

rbx -v: rubinius 2.0.0dev (1.9.3 561610bb yyyy-mm-dd JI) [x86_64-apple-darwin12.1.0]
uname -v: Darwin Kernel Version 12.1.0: Tue Aug 14 13:29:55 PDT 2012; root:xnu-2050.9.2~1/RELEASE_X86_64

--

Expected behavior:

```
$ irb
1.9.3p194 :001 > RUBY_DESCRIPTION
=> "ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.0.0]"
1.9.3p194 :002 > a = BasicObject.new
(Object doesn't support #inspect)
=>
1.9.3p194 :003 > a.instance_eval('self').equal?(a)
=> true
```

Rubinius behavior as of 561610bb:

```
$ bin/rbx
rbx-head :001 > RUBY_DESCRIPTION
=> "rubinius 2.0.0dev (1.9.3 561610bb yyyy-mm-dd JI) [x86_64-apple-darwin12.1.0]"
rbx-head :002 > a = BasicObject.new
(Object doesn't support #inspect)
=>
rbx-head :003 > a.instance_eval('self').equal?(a)
NoMethodError: Unable to send 'StringValue' on instance of BasicObject
from kernel/common/basicobject.rb:5:in `StringValue (method_missing)'
from kernel/common/eval19.rb:47:in `instance_eval'
from (irb):3
from kernel/common/block_environment.rb:75:in `call_on_instance'
from kernel/common/eval.rb:75:in `eval'
from kernel/common/kernel19.rb:42:in `loop'
from kernel/common/throw_catch19.rb:8:in `catch'
from kernel/common/throw_catch.rb:10:in `register'
from kernel/common/throw_catch19.rb:7:in `catch'
from kernel/common/throw_catch19.rb:8:in `catch'
from kernel/common/throw_catch.rb:10:in `register'
from kernel/common/throw_catch19.rb:7:in `catch'
from kernel/common/codeloader.rb:212:in `require'
from kernel/common/kernel.rb:631:in `gem_original_require (require)'
from /Users/trythil/src/rubinius/lib/rubygems/custom_require.rb:36:in `require'
from kernel/loader.rb:680:in `irb'
from kernel/loader.rb:816:in `main'r
```

This pull request contains two commits that address this problem.

The first commit is an addition to RubySpec for this use of BasicObject#instance_eval. The second commit makes a small change to kernel/common/eval19.rb to avoid invoking StringValue, which doesn't exist on BasicObject (since BasicObject doesn't have Kernel as an ancestor).

I'm not crazy about this particular fix; it was just the least invasive alternative I could see. I welcome more concise suggestions.