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

yarv-dev:787

From: 雪見酒 <yukimi_sake mbi.nifty.com>
Date: Sun, 29 Jan 2006 17:31:43 +0900
Subject: [yarv-dev:787] open> probrem of a nested method on instance_eval

こんにちは。
メソッド内でメソッドをネストさせたものをinstance_evalするとおかしくなり
ます。

class A
  class B
    def a_method
      def nested_method
        p "nested_method"
      end
      nested_method
    end
  end

  def test_method
    instance_eval("B.new.a_method")
#    eval("B.new.a_method")
#    B.new.a_method
  end
end

A.new.test_method

結果は

C:\yarv\test>ruby inistance_eval_test2.rb
inistance_eval_test2.rb:12:in `instance_eval': undefined local variable
or method `nested_method' for # (NameError)
        from inistance_eval_test2.rb:7:in `a_method'
        from (eval):1:in `test_method'
        from inistance_eval_test2.rb:12:in `instance_eval'
        from inistance_eval_test2.rb:12:in `test_method'
        from inistance_eval_test2.rb:18:in `'

です。
単にnewしただけとか、evalでは正常です。
--
雪見酒



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

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

->     787 2006-01-29 17:31 [yukimi_sake mbi.nift] open> probrem of a nested method on instance_eval
       793 2006-02-01 03:48 ┗[ko1 atdot.net       ] fixed> Re: open> probrem of a nested method on instance_eval
       794 2006-02-01 08:20  ┗[matz ruby-lang.org  ]