instance_variable_defined?

obj.instance_variable_defined?(symbol) â true or false
Instance Public methods

Returns true if the given instance variable is defined in obj.

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
doc_ruby_on_rails
2015-04-23 17:23:35
Comments
Leave a Comment

Please login to continue.