[前][次][番号順一覧][スレッド一覧][生データ]

yarv-dev:786

From: 雪見酒 <yukimi_sake mbi.nifty.com>
Date: Sun, 29 Jan 2006 17:31:32 +0900
Subject: [yarv-dev:786] open> different scope of eval

こんにちは。
以下のサンプルはRubyとYARVで結果が異なります。

class Hoge
  def fuge
    eval "EvaluatedConst = 10"
    self
  end
end

Hoge.new.fuge
p Hoge::EvaluatedConst
begin
  p EvaluatedConst
rescue
  puts $!
end
p Hoge.module_eval("remove_const :EvaluatedConst")

Rubyの結果

C:\yarv\src\yarv>cd ..\..\test

C:\yarv\test>ruby consttest.rb
10
uninitialized constant EvaluatedConst
10

YARVの結果

C:\yarv\test>ruby consttest.rb
10
10
consttest.rb:15:in `module_eval': (eval):1:in `remove_const': constant
Hoge::EvaluatedConst not defined (NameError)
        from (eval):1:in `'
        from consttest.rb:15:in `module_eval'
        from consttest.rb:15:in `'

--
雪見酒


-- 
ML: yarv-dev quickml.atdot.net
使い方: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧][生データ]

->     786 2006-01-29 17:31 [yukimi_sake mbi.nift] open> different scope of eval           
       789 2006-01-31 02:47 ┣[ko1 atdot.net       ]                                       
       790 2006-02-01 00:14 ┃┗[yukimi_sake mbi.nift]                                     
       791 2006-02-01 01:20 ┃ ┗[ko1 atdot.net       ]                                   
       854 2006-02-13 20:44 ┗[ko1 atdot.net       ] fixed> Re: open> different scope of eval