Class: MyList
- Inherits:
-
Object
- Object
- MyList
- Defined in:
- lib/testing.rb
Class Method Summary collapse
Instance Method Summary collapse
- #append(a) ⇒ Object
- #contents ⇒ Object
- #find_first_position_of(a) ⇒ Object
- #find_positions_of(a) ⇒ Object
-
#initialize(a = []) ⇒ MyList
constructor
A new instance of MyList.
- #maximum ⇒ Object
- #min_max_fast ⇒ Object
- #min_max_slow ⇒ Object
- #minimum_correct ⇒ Object
- #minimum_wrong ⇒ Object
Constructor Details
#initialize(a = []) ⇒ MyList
Returns a new instance of MyList.
7 8 9 |
# File 'lib/testing.rb', line 7 def initialize(a = []) @list = a end |
Class Method Details
.set_correct ⇒ Object
108 109 110 |
# File 'lib/testing.rb', line 108 def self.set_correct alias_method :minimum, :minimum_correct end |
.set_fast ⇒ Object
100 101 102 |
# File 'lib/testing.rb', line 100 def self.set_fast alias_method :min_max, :min_max_fast end |
.set_slow ⇒ Object
96 97 98 |
# File 'lib/testing.rb', line 96 def self.set_slow alias_method :min_max, :min_max_slow end |
.set_wrong ⇒ Object
104 105 106 |
# File 'lib/testing.rb', line 104 def self.set_wrong alias_method :minimum, :minimum_wrong end |
Instance Method Details
#append(a) ⇒ Object
15 16 17 |
# File 'lib/testing.rb', line 15 def append(a) @list.append(a) end |
#contents ⇒ Object
11 12 13 |
# File 'lib/testing.rb', line 11 def contents @list end |
#find_first_position_of(a) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/testing.rb', line 19 def find_first_position_of(a) i = 0 position = nil while i < @list.length if @list[i] == a position = i break end i += 1 end return position end |
#find_positions_of(a) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/testing.rb', line 32 def find_positions_of(a) positions = [] i = 0 while i < @list.length if @list[i] == a positions.append i end i += 1 end return positions end |
#maximum ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/testing.rb', line 44 def maximum i = 0 max = @list[0] while i < @list.length if @list[i] > max max = @list[i] end i += 1 end return max end |
#min_max_fast ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/testing.rb', line 84 def min_max_fast i = 0 min = @list[0] max = @list[0] while i < @list.length min = @list[i] if @list[i] < min max = @list[i] if @list[i] > max i += 1 end [min, max] end |
#min_max_slow ⇒ Object
80 81 82 |
# File 'lib/testing.rb', line 80 def min_max_slow [minimum, maximum] end |
#minimum_correct ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/testing.rb', line 68 def minimum_correct i = 0 min = @list[0] while i < @list.length if @list[i] < min min = @list[i] end i += 1 end return min end |
#minimum_wrong ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/testing.rb', line 56 def minimum_wrong i = 0 min = @list[0] while i < @list.length if @list[i] > min min = @list[i] end i += 1 end return min end |