Module: Concurrent::ImmutableStruct
- Defined in:
- lib/concurrent-ruby/concurrent/immutable_struct.rb
Overview
A thread-safe, immutable variation of Ruby’s standard Struct.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Equality.
-
#[](member) ⇒ Object
Attribute Reference.
-
#each {|value| ... } ⇒ Object
Yields the value of each struct member in order.
-
#each_pair {|member, value| ... } ⇒ Object
Yields the name and value of each struct member in order.
-
#inspect ⇒ String
(also: #to_s)
Describe the contents of this struct in a string.
-
#merge(other) {|member, selfvalue, othervalue| ... } ⇒ Synchronization::AbstractStruct
Returns a new struct containing the contents of
otherand the contents ofself. -
#select {|value| ... } ⇒ Array
Yields each member value from the struct to the block and returns an Array containing the member values from the struct for which the given block returns a true value (equivalent to ‘Enumerable#select`).
-
#to_h ⇒ Hash
Returns a hash containing the names and values for the struct’s members.
-
#values ⇒ Array
(also: #to_a)
Returns the values for this struct as an Array.
-
#values_at(*indexes) ⇒ Object
Returns the struct member values for each selector as an Array.
Class Method Details
.included(base) ⇒ Object
12 13 14 |
# File 'lib/concurrent-ruby/concurrent/immutable_struct.rb', line 12 def self.included(base) base.safe_initialization! end |
Instance Method Details
#==(other) ⇒ Boolean
Equality
51 52 53 |
# File 'lib/concurrent-ruby/concurrent/immutable_struct.rb', line 51 def ==(other) ns_equality(other) end |
#[](member) ⇒ Object
Attribute Reference
46 47 48 |
# File 'lib/concurrent-ruby/concurrent/immutable_struct.rb', line 46 def [](member) ns_get(member) end |
#each {|value| ... } ⇒ Object
Yields the value of each struct member in order. If no block is given an enumerator is returned.
56 57 58 59 |
# File 'lib/concurrent-ruby/concurrent/immutable_struct.rb', line 56 def each(&block) return enum_for(:each) unless block_given? ns_each(&block) end |
#each_pair {|member, value| ... } ⇒ Object
Yields the name and value of each struct member in order. If no block is given an enumerator is returned.
62 63 64 65 |
# File 'lib/concurrent-ruby/concurrent/immutable_struct.rb', line 62 def each_pair(&block) return enum_for(:each_pair) unless block_given? ns_each_pair(&block) end |
#inspect ⇒ String Also known as: to_s
Describe the contents of this struct in a string.
29 30 31 |
# File 'lib/concurrent-ruby/concurrent/immutable_struct.rb', line 29 def inspect ns_inspect end |
#merge(other) {|member, selfvalue, othervalue| ... } ⇒ Synchronization::AbstractStruct
Returns a new struct containing the contents of other and the contents of self. If no block is specified, the value for entries with duplicate keys will be that of other. Otherwise the value for each duplicate key is determined by calling the block with the key, its value in self and its value in other.
36 37 38 |
# File 'lib/concurrent-ruby/concurrent/immutable_struct.rb', line 36 def merge(other, &block) ns_merge(other, &block) end |
#select {|value| ... } ⇒ Array
Yields each member value from the struct to the block and returns an Array containing the member values from the struct for which the given block returns a true value (equivalent to ‘Enumerable#select`).
68 69 70 71 |
# File 'lib/concurrent-ruby/concurrent/immutable_struct.rb', line 68 def select(&block) return enum_for(:select) unless block_given? ns_select(&block) end |
#to_h ⇒ Hash
Returns a hash containing the names and values for the struct’s members.
41 42 43 |
# File 'lib/concurrent-ruby/concurrent/immutable_struct.rb', line 41 def to_h ns_to_h end |
#values ⇒ Array Also known as: to_a
Returns the values for this struct as an Array.
17 18 19 |
# File 'lib/concurrent-ruby/concurrent/immutable_struct.rb', line 17 def values ns_values end |
#values_at(*indexes) ⇒ Object
Returns the struct member values for each selector as an Array.
A selector may be either an Integer offset or a Range of offsets (as in ‘Array#values_at`).
24 25 26 |
# File 'lib/concurrent-ruby/concurrent/immutable_struct.rb', line 24 def values_at(*indexes) ns_values_at(indexes) end |