[#49993] メソッド呼び出し時の引数の値を VM 側で取得する方法について — Tetsuo Handa <penguin-kernel@...>

初めまして。 Linux カーネルプログラマの熊猫と申します。

12 messages 2017/02/28
[#49995] Re: メソッド呼び出し時の引数の値を VM 側で取得する方法について — SASADA Koichi <ko1@...> 2017/02/28

On 2017/02/28 14:06, Tetsuo Handa wrote:

[ruby-dev:49980] [Ruby trunk Bug#13204][Closed] Search order of constant is different

From: nobu@...
Date: 2017-02-10 04:31:03 UTC
List: ruby-dev #49980
Issue #13204 has been updated by Nobuyoshi Nakada.

Status changed from Open to Closed

Intentional.
Top level constants are constants defined in `Object`, but `BasicObject` does not inherit `Object`.

----------------------------------------
Bug #13204: Search order of constant is different
https://bugs.ruby-lang.org/issues/13204#change-62942

* Author: okkez _
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
```ruby
class CleanRoom < BasicObject
  def call
    instance_eval(<<-CODE)
    $stdout.puts ::ENV.size
    CODE
  end

  def call2
    instance_eval(<<-CODE)
    $stdout.puts ENV.size
    CODE
  end

  def call3
    instance_eval { $stdout.puts ::ENV.size }
  end
end

class CleanRoom2
  def call
    instance_eval(<<-CODE)
    $stdout.puts ENV.size
    CODE
  end
end

CleanRoom.new.call # => 80 (in my environment)
CleanRoom2.new.call # => 80
CleanRoom.new.call3 # => 80
CleanRoom.new.call2 # => t.rb:14:in `instance_eval': uninitialized constant #<Class:#<CleanRoom:0x0055698d201da8>>::ENV (NameError)
```

`CleanRoom` instance cannot refer constants defined in top level.
Is this intentional?




-- 
https://bugs.ruby-lang.org/

In This Thread

Prev Next