Module: STL
- Included in:
- FunctioncallNode
- Defined in:
- lib/STL.rb
Class Method Summary collapse
- .delete_element(array, index) ⇒ Object
- .get_element(array, index) ⇒ Object
- .pop(array) ⇒ Object
- .print(x) ⇒ Object
- .push(array, element) ⇒ Object
- .size(array) ⇒ Object
Class Method Details
.delete_element(array, index) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/STL.rb', line 48 def self.delete_element(array, index) unless array.is_a?(Array) raise TypeError, "Function #{__method__} must be used on an array." end unless index.between?(0, array.size-1) raise IndexError, "Index out of bounds. Max index: #{array.size-1}." end element = array[index] array.delete_at(index) return element end |
.get_element(array, index) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/STL.rb', line 36 def self.get_element(array, index) unless array.is_a?(Array) raise TypeError, "Function #{__method__} must be used on an array." end unless index.between?(0, array.size-1) raise IndexError, "Index out of bounds. Max index: #{array.size-1}." end element = array[index] return element end |
.pop(array) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/STL.rb', line 16 def self.pop(array) unless array.is_a?(Array) raise TypeError, "Function #{__method__} must be used on an array." end if array.empty? raise IndexError, "Can not use pop on an empty array." end pop_element = array.last array.delete_at(-1) return pop_element end |
.print(x) ⇒ Object
3 4 5 6 |
# File 'lib/STL.rb', line 3 def self.print(x) pp x return nil end |
.push(array, element) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/STL.rb', line 28 def self.push(array, element) unless array.is_a?(Array) raise TypeError, "Function #{__method__} must be used on an array." end array << element return array end |
.size(array) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/STL.rb', line 8 def self.size(array) unless array.is_a?(Array) raise TypeError, "Function #{__method__} must be used on an array." end return array.count end |