module Concurrent::MutableStruct

def self.new(*args, &block)

@!macro struct_new
def self.new(*args, &block)
  clazz_name = nil
  if args.length == 0
    raise ArgumentError.new('wrong number of arguments (0 for 1+)')
  elsif args.length > 0 && args.first.is_a?(String)
    clazz_name = args.shift
  end
  FACTORY.define_struct(clazz_name, args, &block)
end

def ==(other)

Returns:
  • (Boolean) - true if other has the same struct subclass and has
def ==(other)
  synchronize { ns_equality(other) }
end

def [](member)

Raises:
  • (IndexError) - if the index is out of range.
  • (NameError) - if the member does not exist

Returns:
  • (Object) - the value of the given struct member or the member at the given index.

Parameters:
  • member (Symbol, String, Integer) -- the string or symbol name of the member
def [](member)
  synchronize { ns_get(member) }
end

def []=(member, value)

Raises:
  • (IndexError) - if the index is out of range.
  • (NameError) - if the name does not exist

Returns:
  • (Object) - the value of the given struct member or the member at the given index.

Parameters:
  • member (Symbol, String, Integer) -- the string or symbol name of the member
def []=(member, value)
  if member.is_a? Integer
    length = synchronize { @values.length }
    if member >= length
      raise IndexError.new("offset #{member} too large for struct(size:#{length})")
    end
    synchronize { @values[member] = value }
  else
    send("#{member}=", value)
  end
rescue NoMethodError
  raise NameError.new("no member '#{member}' in struct")
end

def each(&block)

Other tags:
    Yieldparam: value - each struct value (in order)

Other tags:
    Yield: - the operation to be performed on each struct member
def each(&block)
  return enum_for(:each) unless block_given?
  synchronize { ns_each(&block) }
end

def each_pair(&block)

Other tags:
    Yieldparam: value - each struct value (in order)
    Yieldparam: member - each struct member (in order)

Other tags:
    Yield: - the operation to be performed on each struct member/value pair
def each_pair(&block)
  return enum_for(:each_pair) unless block_given?
  synchronize { ns_each_pair(&block) }
end

def initialize_copy(original)

@!visibility private
def initialize_copy(original)
  synchronize do
    super(original)
    ns_initialize_copy
  end
end

def inspect

Returns:
  • (String) - the contents of this struct in a string
def inspect
  synchronize { ns_inspect }
end

def merge(other, &block)

Raises:
  • (ArgumentError) - of given a member that is not defined in the struct

Returns:
  • (Synchronization::AbstractStruct) - a new struct with the new values

Other tags:
    Yieldparam: othervalue - the value of the member in `other`
    Yieldparam: selfvalue - the value of the member in `self`
    Yieldparam: member - the name of the member which is duplicated

Other tags:
    Yield: - an options block for resolving duplicate keys

Parameters:
  • other (Hash) -- the hash from which to set the new values
def merge(other, &block)
  synchronize { ns_merge(other, &block) }
end

def select(&block)

Returns:
  • (Array) - an array containing each value for which the block returns true

Other tags:
    Yieldparam: value - each struct value (in order)

Other tags:
    Yield: - the operation to be performed on each struct member
def select(&block)
  return enum_for(:select) unless block_given?
  synchronize { ns_select(&block) }
end

def to_h

Returns:
  • (Hash) - the names and values for the struct’s members
def to_h
  synchronize { ns_to_h }
end

def values

Returns:
  • (Array) - the values for this struct
def values
  synchronize { ns_values }
end

def values_at(*indexes)

Parameters:
  • indexes (Fixnum, Range) -- the index(es) from which to obatin the values (in order)
def values_at(*indexes)
  synchronize { ns_values_at(indexes) }
end