Class: Tkri::History
- Inherits:
-
Object
- Object
- Tkri::History
- Defined in:
- lib/tkri.rb
Instance Method Summary collapse
- #add(entry) ⇒ Object
- #at_beginning ⇒ Object
- #at_end ⇒ Object
- #back ⇒ Object
- #current ⇒ Object
- #foreward ⇒ Object
-
#initialize ⇒ History
constructor
A new instance of History.
- #size ⇒ Object
Constructor Details
#initialize ⇒ History
Returns a new instance of History.
199 200 201 202 |
# File 'lib/tkri.rb', line 199 def initialize @arr = [] @current = -1 end |
Instance Method Details
#add(entry) ⇒ Object
229 230 231 232 233 234 |
# File 'lib/tkri.rb', line 229 def add(entry) @current += 1 @arr[@current] = entry # Adding an entry removes all entries in the "future". @arr.slice!(@current + 1, @arr.size) end |
#at_beginning ⇒ Object
236 237 238 |
# File 'lib/tkri.rb', line 236 def at_beginning @current <= 0 end |
#at_end ⇒ Object
240 241 242 |
# File 'lib/tkri.rb', line 240 def at_end @current == @arr.size - 1; end |
#back ⇒ Object
216 217 218 219 220 221 |
# File 'lib/tkri.rb', line 216 def back if @current > 0 @current -= 1 end current end |
#current ⇒ Object
208 209 210 211 212 213 214 |
# File 'lib/tkri.rb', line 208 def current if @current >= 0 @arr[@current] else nil end end |
#foreward ⇒ Object
223 224 225 226 227 |
# File 'lib/tkri.rb', line 223 def foreward if @current < @arr.size - 1 @current += 1 end end |
#size ⇒ Object
204 205 206 |
# File 'lib/tkri.rb', line 204 def size @arr.size end |