Class: NBTFile::Types::List
- Inherits:
-
Object
- Object
- NBTFile::Types::List
- Includes:
- Enumerable, Private::Base
- Defined in:
- lib/nbtfile.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #<<(item) ⇒ Object
- #==(other) ⇒ Object
- #each ⇒ Object
-
#initialize(type, items = []) ⇒ List
constructor
A new instance of List.
- #length ⇒ Object (also: #size)
- #to_a ⇒ Object
Constructor Details
#initialize(type, items = []) ⇒ List
Returns a new instance of List.
917 918 919 920 921 922 923 |
# File 'lib/nbtfile.rb', line 917 def initialize(type, items=[]) @type = type @items = [] for item in items self << item end end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
915 916 917 |
# File 'lib/nbtfile.rb', line 915 def type @type end |
Instance Method Details
#<<(item) ⇒ Object
925 926 927 928 929 930 931 |
# File 'lib/nbtfile.rb', line 925 def <<(item) unless item.instance_of? @type raise TypeError, "Items should be instances of #{@type}" end @items << item self end |
#==(other) ⇒ Object
951 952 953 |
# File 'lib/nbtfile.rb', line 951 def ==(other) self.class == other.class && @items == other.to_a end |
#each ⇒ Object
933 934 935 936 937 938 939 940 |
# File 'lib/nbtfile.rb', line 933 def each if block_given? @items.each { |item| yield item } self else @items.each end end |
#length ⇒ Object Also known as: size
946 947 948 |
# File 'lib/nbtfile.rb', line 946 def length @items.length end |
#to_a ⇒ Object
942 943 944 |
# File 'lib/nbtfile.rb', line 942 def to_a @items.dup end |