class Wallaby::ClassArray
This is a constant-safe array that stores Class value as String.
Attributes
internal[R]
@!attribute [r] internal @return [Array] The array to store Class values as String.
Public Class Methods
new(array = [])
click to toggle source
@param [Array] array
# File lib/wallaby/class_array.rb, line 9 def initialize(array = []) @internal = array || [] return if @internal.blank? @internal.map!(&method(:to_class_name)).compact! end
Public Instance Methods
-(other)
click to toggle source
@param other [Array] @return [Wallaby::ClassArray] new Class array
# File lib/wallaby/class_array.rb, line 45 def -(other) self.class.new origin - (other.try(:origin) || other) end
[](index)
click to toggle source
Return the value for the given index
# File lib/wallaby/class_array.rb, line 33 def [](index) to_class @internal[index] end
[]=(index, value)
click to toggle source
Save the value to the {#internal} array at the given index, and convert the Class value to String
# File lib/wallaby/class_array.rb, line 28 def []=(index, value) @internal[index] = to_class_name value end
concat(other)
click to toggle source
@param other [Array] @return [Wallaby::ClassArray] new Class array
# File lib/wallaby/class_array.rb, line 39 def concat(other) self.class.new origin.concat(other.try(:origin) || other) end
each(&block)
click to toggle source
@return [Wallaby::ClassArray] self
# File lib/wallaby/class_array.rb, line 50 def each(&block) origin.each(&block) self end
freeze()
click to toggle source
Ensure to freeze the {#internal} @return [Wallaby::ClassArray] self
Calls superclass method
# File lib/wallaby/class_array.rb, line 70 def freeze @internal.freeze super end
origin()
click to toggle source
@!attribute [r] origin @return [Array] The original array.
# File lib/wallaby/class_array.rb, line 22 def origin # NOTE: DO NOT cache it by using instance variable! @internal.map(&method(:to_class)).compact end