Class: CowProxy::Array
- Includes:
- Indexable, Enumerable
- Defined in:
- lib/cow_proxy/array.rb
Overview
Wrapper class for Array
Instance Method Summary collapse
-
#each {|item| ... } ⇒ CowProxy::Array, Enumerator
Calls the given block once for each element in self, passing wrapped element as a parameter.
-
#map! {|item| ... } ⇒ CowProxy::Array, Enumerator
(also: #collect!)
Invokes the given block once for each element of self, replacing the element with the value returned by the block.
-
#to_ary ⇒ Array
Used for concatenating into another Array needs to return unwrapped Array.
Methods included from Indexable
Instance Method Details
#each {|item| ... } ⇒ CowProxy::Array, Enumerator
Calls the given block once for each element in self, passing wrapped element as a parameter.
15 16 17 18 19 20 21 |
# File 'lib/cow_proxy/array.rb', line 15 def each return enum_for(:each) unless block_given? __getobj__.each.with_index do |_, i| yield self[i] end self end |
#map! {|item| ... } ⇒ CowProxy::Array, Enumerator Also known as: collect!
Invokes the given block once for each element of self, replacing the element with the value returned by the block.
31 32 33 34 35 36 37 |
# File 'lib/cow_proxy/array.rb', line 31 def map! __copy_on_write__ return enum_for(:map!) unless block_given? __getobj__.each.with_index do |_, i| self[i] = yield(self[i]) end end |
#to_ary ⇒ Array
Used for concatenating into another Array needs to return unwrapped Array
44 45 46 |
# File 'lib/cow_proxy/array.rb', line 44 def to_ary __getobj__ end |