Class: Xavier::State Private

Inherits:
BasicObject
Defined in:
lib/xavier/state.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A storage for an observed class or object’s internal state.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(observed_object_id) ⇒ State

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new state representation.

Parameters:

  • observed_object_id (Integer)

    The object_id of the observed object.



15
16
17
18
19
# File 'lib/xavier/state.rb', line 15

def initialize(observed_object_id)
  @observed_object_id = observed_object_id
  @class_variables = {}
  @instance_variables = {}
end

Instance Attribute Details

#observed_object_idInteger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the object id of the observed object

Returns:

  • (Integer)

    The object_id of the observed object.



10
11
12
# File 'lib/xavier/state.rb', line 10

def observed_object_id
  @observed_object_id
end

Instance Method Details

#classState

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the class State.

Returns:

  • (State)

    The class State.



70
71
72
# File 'lib/xavier/state.rb', line 70

def class
  State
end

#class_variable_get(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the value of the given class variable, or nil if the class variable is not set.

Parameters:

  • name (String|Symbol)

    Name of the class variable.

Returns:

  • The value of the given class variable.



55
56
57
# File 'lib/xavier/state.rb', line 55

def class_variable_get(name)
  @class_variables[name.to_sym]
end

#class_variable_set(name, value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Sets the class variable named by name to the given object.

Parameters:

  • name (String|Symbol)

    Name of the instance variable.

  • value

    Value of the instance variable.

Returns:

  • The value of the given class variable.



46
47
48
# File 'lib/xavier/state.rb', line 46

def class_variable_set(name, value)
  @class_variables[name.to_sym] = value
end

#class_variablesArray<Symbol>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns an array of the names of class variables in mod.

Returns:

  • (Array<Symbol>)

    Array of class variable names.



84
85
86
# File 'lib/xavier/state.rb', line 84

def class_variables
  @class_variables.keys
end

#instance_variable_get(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the value of the given instance variable, or nil if the instance variable is not set.

Parameters:

  • name (String|Symbol)

    Name of the instance variable.

Returns:

  • The value of the given instance variable.



36
37
38
# File 'lib/xavier/state.rb', line 36

def instance_variable_get(name)
  @instance_variables[name.to_sym]
end

#instance_variable_set(name, value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Sets the instance variable named by name to the given object.

Parameters:

  • name (String|Symbol)

    Name of the instance variable.

  • value

    Value of the instance variable.

Returns:

  • The value of the given instance variable.



27
28
29
# File 'lib/xavier/state.rb', line 27

def instance_variable_set(name, value)
  @instance_variables[name.to_sym] = value
end

#instance_variablesArray<Symbol>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns an array of instance variable names for the receiver.

Returns:

  • (Array<Symbol>)

    Array of instance variable names.



77
78
79
# File 'lib/xavier/state.rb', line 77

def instance_variables
  @instance_variables.keys
end

#is_a?(clazz) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns true if class is the class of self, or if clazz is one of the superclasses of self or modules.

Returns:

  • (Boolean)

    Whether the given class is the class, superclass or modules of self.



62
63
64
65
# File 'lib/xavier/state.rb', line 62

def is_a?(clazz)
  return true if clazz == ::Class
  self.class == clazz
end