Module: Mongoid::Extensions::Object::Reflections

Extended by:
ActiveSupport::Concern
Included in:
Object
Defined in:
lib/mongoid/extensions/object/reflections.rb

Overview

This module contains reflection convenience methods.

Instance Method Summary collapse

Instance Method Details

#ivar(name) ⇒ Object?

Get the value for an instance variable or nil if it doesn’t exist.

Examples:

Get the value for an instance var.

document.ivar("person")

Parameters:

  • name (String)

    The name of the variable.

Returns:

  • (Object, nil)

    The value or nil.

Since:

  • 2.0.0.rc.1



20
21
22
23
24
25
26
# File 'lib/mongoid/extensions/object/reflections.rb', line 20

def ivar(name)
  if instance_variable_defined?("@#{name}")
    return instance_variable_get("@#{name}")
  else
    false
  end
end

#remove_ivar(name) ⇒ true, false

Remove the instance variable for the provided name.

Examples:

Remove the instance variable

document.remove_ivar("person")

Parameters:

  • name (String)

    The name of the variable.

Returns:

  • (true, false)

    If the variable was defined.

Since:

  • 2.1.0



38
39
40
41
42
43
44
# File 'lib/mongoid/extensions/object/reflections.rb', line 38

def remove_ivar(name)
  if instance_variable_defined?("@#{name}")
    return remove_instance_variable("@#{name}")
  else
    false
  end
end