2011-06-18 28 views
0

我一直在研究我的Ruby。當試圖執行從Ruby Object documentation這個簡單的例子,我得到這個錯誤:ruby​​ 1.8未定義方法`instance_variable_defined?'

undefined method `instance_variable_defined?'

這是我的代碼:

class Fred 
    def initialize(p1, p2) 
    @a, @b = p1, p2 
    end 
end 

fred = Fred.new('cat', 99) 
fred.instance_variable_defined?(:@a) #=> true 
fred.instance_variable_defined?("@b") #=> true 
fred.instance_variable_defined?("@c") #=> false 

我做了什麼錯?我在Ubuntu 10.04的另一臺機器上測試了它,它工作正常。順便說一下,我使用的是Centos 5.5。

有誰知道如何解決這個問題?

+4

告訴你已安裝的Ruby版本。 –

回答

3

我能想到的唯一的事情是,你正在使用Ruby的古代版(1.8.5或更早),因爲1.8.6作爲Object#instance_variable_defined?一直在Ruby中。

+0

感謝您的答覆傢伙,dmarkow是正確的,我使用Ruby 1.8.5會學嘗試升級到1.8.6,所以我可以開始使用的DataMapper庫。 – jameslimousin

+0

如果你要升級,你還不如用最新的1.8分支(1.8.7)的。 http://rvm.beginrescueend.com可能是您最好的最好的安裝。 –

相關問題