开发者

ruby 1.8 undefined method `instance_variable_defined?'

开发者 https://www.devze.com 2023-03-14 08:16 出处:网络
I have been working on my Ruby. When trying to execute this simple example from th开发者_开发技巧e Ruby Object documentation, I get this error:

I have been working on my Ruby. When trying to execute this simple example from th开发者_开发技巧e Ruby Object documentation, I get this error:

undefined method `instance_variable_defined?'

This is my code:

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

What have I done wrong? I tested this on another machine with Ubuntu 10.04 and it works fine. I'm using Centos 5.5 by the way.

Does anyone knows how to fix this?


The only thing I can think of is that you're using an ancient version of Ruby (1.8.5 or earlier), as Object#instance_variable_defined? has been in Ruby since 1.8.6.

0

精彩评论

暂无评论...
验证码 换一张
取 消