Class: Tuple
- Inherits:
-
Object
- Object
- Tuple
- Defined in:
- lib/static_ruby.rb
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#first ⇒ Object
readonly
Returns the value of attribute first.
-
#last ⇒ Object
readonly
Returns the value of attribute last.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #!=(o) ⇒ Object
- #==(o) ⇒ Object
- #[](i) ⇒ Object
- #[]=(_, _) ⇒ Object
- #each(&block) ⇒ Object
- #each_with_index(&block) ⇒ Object
-
#initialize(*elements) ⇒ Tuple
constructor
A new instance of Tuple.
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*elements) ⇒ Tuple
Returns a new instance of Tuple.
70 71 72 73 74 75 |
# File 'lib/static_ruby.rb', line 70 def initialize(*elements) @elements = elements @size = elements.size @first = elements.size != 0 ? elements[0] : nil @last = elements.size != 0 ? elements[-1] : nil end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
68 69 70 |
# File 'lib/static_ruby.rb', line 68 def elements @elements end |
#first ⇒ Object (readonly)
Returns the value of attribute first.
68 69 70 |
# File 'lib/static_ruby.rb', line 68 def first @first end |
#last ⇒ Object (readonly)
Returns the value of attribute last.
68 69 70 |
# File 'lib/static_ruby.rb', line 68 def last @last end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
68 69 70 |
# File 'lib/static_ruby.rb', line 68 def size @size end |
Instance Method Details
#!=(o) ⇒ Object
89 90 91 |
# File 'lib/static_ruby.rb', line 89 def !=(o) @elements != o.elements end |
#==(o) ⇒ Object
85 86 87 |
# File 'lib/static_ruby.rb', line 85 def ==(o) @elements == o.elements end |
#[](i) ⇒ Object
93 94 95 |
# File 'lib/static_ruby.rb', line 93 def [](i) @elements[i] end |
#[]=(_, _) ⇒ Object
97 98 99 |
# File 'lib/static_ruby.rb', line 97 def []=(_, _) raise('Tuple cannot be modified') end |
#each(&block) ⇒ Object
101 102 103 104 105 |
# File 'lib/static_ruby.rb', line 101 def each(&block) @elements.each do |x| block.call(x) end end |
#each_with_index(&block) ⇒ Object
107 108 109 110 111 |
# File 'lib/static_ruby.rb', line 107 def each_with_index(&block) @elements.each_with_index do |x, i| block.call(x, i) end end |
#to_a ⇒ Object
77 78 79 |
# File 'lib/static_ruby.rb', line 77 def to_a @elements end |
#to_s ⇒ Object
81 82 83 |
# File 'lib/static_ruby.rb', line 81 def to_s "Tuple(#{@elements.map { |x| x.to_s }})" end |