module Concurrent::MutableStruct
def self.new(*args, &block)
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)
-
(Boolean)
- true if other has the same struct subclass and has
def ==(other) synchronize { ns_equality(other) } end
def [](member)
-
(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)
-
(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)
- 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)
- 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)
def initialize_copy(original) synchronize do super(original) ns_initialize_copy end end
def inspect
-
(String)
- the contents of this struct in a string
def inspect synchronize { ns_inspect } end
def merge(other, &block)
-
(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)
-
(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
-
(Hash)
- the names and values for the struct’s members
def to_h synchronize { ns_to_h } end
def values
-
(Array)
- the values for this struct
def values synchronize { ns_values } end
def values_at(*indexes)
-
indexes
(Fixnum, Range
) -- the index(es) from which to obatin the values (in order)
def values_at(*indexes) synchronize { ns_values_at(indexes) } end