class Canis::History
— History
class {{{ just so the program does not bomb due to a tiny feature I do not raise error on nil array, i create a dummy array which you likely will not be able to use, in any case it will have only one value
Enable field history on UP and DOWN during rb_getstr
Attributes
array[R]
current_index[R]
last_index[R]
Public Class Methods
new(a=nil, c=0)
click to toggle source
# File lib/canis/core/util/extras/bottomline.rb, line 36 def initialize a=nil, c=0 #raise "Array passed to History cannot be nil" unless a #@max_index = a.size @array = a || [] @current_index = c @last_index = c end
Public Instance Methods
first()
click to toggle source
# File lib/canis/core/util/extras/bottomline.rb, line 47 def first @current_index = 0 @array.first end
is_last?()
click to toggle source
# File lib/canis/core/util/extras/bottomline.rb, line 77 def is_last? @current_index == max_index() end
last()
click to toggle source
# File lib/canis/core/util/extras/bottomline.rb, line 43 def last @current_index = max_index @array.last end
max_index()
click to toggle source
# File lib/canis/core/util/extras/bottomline.rb, line 51 def max_index @array.size - 1 end
next()
click to toggle source
# File lib/canis/core/util/extras/bottomline.rb, line 59 def next @last_index = @current_index if @current_index + 1 > max_index @current_index = 0 else @current_index += 1 end @array[@current_index] end
previous()
click to toggle source
# File lib/canis/core/util/extras/bottomline.rb, line 68 def previous @last_index = @current_index if @current_index - 1 < 0 @current_index = max_index() else @current_index -= 1 end @array[@current_index] end
push(item)
click to toggle source
# File lib/canis/core/util/extras/bottomline.rb, line 80 def push item $log.debug " XXX history push #{item} " if $log.debug? @array.push item @current_index = max_index end
up()
click to toggle source
# File lib/canis/core/util/extras/bottomline.rb, line 54 def up item = @array[@current_index] previous return item end