module Concurrent::SettableStruct
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)
def ==(other) synchronize { ns_equality(other) } end
def [](member)
def [](member) synchronize { ns_get(member) } end
def []=(member, value)
-
(Concurrent::ImmutabilityError)
- if the given member has already been set
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 do unless @values[member].nil? raise Concurrent::ImmutabilityError.new('struct member has already been set') end @values[member] = value end else send("#{member}=", value) end rescue NoMethodError raise NameError.new("no member '#{member}' in struct") end
def each(&block)
def each(&block) return enum_for(:each) unless block_given? synchronize { ns_each(&block) } end
def each_pair(&block)
def each_pair(&block) return enum_for(:each_pair) unless block_given? synchronize { ns_each_pair(&block) } end
def inspect
def inspect synchronize { ns_inspect } end
def merge(other, &block)
def merge(other, &block) synchronize { ns_merge(other, &block) } end
def select(&block)
def select(&block) return enum_for(:select) unless block_given? synchronize { ns_select(&block) } end
def to_h
def to_h synchronize { ns_to_h } end
def values
def values synchronize { ns_values } end
def values_at(*indexes)
def values_at(*indexes) synchronize { ns_values_at(indexes) } end