Class: Naksh::History

Inherits:
Array
  • Object
show all
Defined in:
lib/naksh/history.rb

Overview

an a subclass of Array which represents a record of entered scripts

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Array

#string

Constructor Details

#initialize(*a) ⇒ History

Returns a new instance of History.



39
40
41
42
43
# File 'lib/naksh/history.rb', line 39

def initialize *a
  super
  a.empty? ? nil : @position=length-1
  self
end

Instance Attribute Details

#positionObject

Returns the value of attribute position.



46
47
48
# File 'lib/naksh/history.rb', line 46

def position
  @position
end

Instance Method Details

#at!(index) ⇒ Object



48
49
50
51
# File 'lib/naksh/history.rb', line 48

def at!(index)
  @position=index
  self[@position]
end

#backObject



63
64
65
66
# File 'lib/naksh/history.rb', line 63

def back
  return self[@position-1] unless @position<1
  nil
end

#back!Object



68
69
70
71
# File 'lib/naksh/history.rb', line 68

def back!
  @position-=1 unless @position < 1
  self[@position]
end

#first!Object



53
54
55
56
# File 'lib/naksh/history.rb', line 53

def first!
  @position=0
  self[@position]
end

#forwardObject



73
74
75
76
# File 'lib/naksh/history.rb', line 73

def forward
  return self[@position+1] unless position+1==length
  nil
end

#forward!Object



78
79
80
81
# File 'lib/naksh/history.rb', line 78

def forward!
  @position+=1 unless @position+1==length
  self[@position]
end

#last!Object



58
59
60
61
# File 'lib/naksh/history.rb', line 58

def last!
  @position=length-1
  self[@position]
end