Class: ProtocolBuffers::RepeatedField
- Inherits:
-
Array
- Object
- Array
- ProtocolBuffers::RepeatedField
- Defined in:
- lib/protocol_buffers/runtime/field.rb
Overview
Acts like an Array, but type-checks each element
Instance Method Summary collapse
-
#<<(obj) ⇒ Object
ovverride all mutating methods.
- #[]=(*args) ⇒ Object
- #collect!(&b) ⇒ Object (also: #map!)
- #concat(rhs) ⇒ Object
- #fill(*args, &b) ⇒ Object
-
#initialize(field) ⇒ RepeatedField
constructor
:nodoc:.
- #insert(index, *objs) ⇒ Object
- #push(*objs) ⇒ Object
- #replace(array) ⇒ Object
- #unshift(*objs) ⇒ Object
Constructor Details
#initialize(field) ⇒ RepeatedField
:nodoc:
19 20 21 22 |
# File 'lib/protocol_buffers/runtime/field.rb', line 19 def initialize(field) super() @field = field end |
Instance Method Details
#<<(obj) ⇒ Object
ovverride all mutating methods. I’m sure this will break down on each new major Ruby release, as new mutating methods are added to Array. Ah, well. caveat emptor.
28 29 30 31 |
# File 'lib/protocol_buffers/runtime/field.rb', line 28 def <<(obj) check(obj) super end |
#[]=(*args) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/protocol_buffers/runtime/field.rb', line 33 def []=(*args) obj = args.last case obj when nil check(obj) if args.length == 2 && !args.first.is_a?(Range) when Array check_each(obj) else check(obj) end super end |
#collect!(&b) ⇒ Object Also known as: map!
46 47 48 |
# File 'lib/protocol_buffers/runtime/field.rb', line 46 def collect!(&b) replace(collect(&b)) end |
#concat(rhs) ⇒ Object
51 52 53 54 |
# File 'lib/protocol_buffers/runtime/field.rb', line 51 def concat(rhs) check_each(rhs) super end |
#fill(*args, &b) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/protocol_buffers/runtime/field.rb', line 56 def fill(*args, &b) if block_given? super(*args) { |v| check(b.call(v)) } else check(args.first) super end end |
#insert(index, *objs) ⇒ Object
65 66 67 68 |
# File 'lib/protocol_buffers/runtime/field.rb', line 65 def insert(index, *objs) check_each(objs) super end |
#push(*objs) ⇒ Object
70 71 72 73 |
# File 'lib/protocol_buffers/runtime/field.rb', line 70 def push(*objs) check_each(objs) super end |
#replace(array) ⇒ Object
75 76 77 78 |
# File 'lib/protocol_buffers/runtime/field.rb', line 75 def replace(array) check_each(array) super end |
#unshift(*objs) ⇒ Object
80 81 82 83 |
# File 'lib/protocol_buffers/runtime/field.rb', line 80 def unshift(*objs) check_each(objs) super end |