Class: Naksh::History
Overview
an a subclass of Array which represents a record of entered scripts
Instance Attribute Summary collapse
-
#position ⇒ Object
Returns the value of attribute position.
Instance Method Summary collapse
- #at!(index) ⇒ Object
- #back ⇒ Object
- #back! ⇒ Object
- #first! ⇒ Object
- #forward ⇒ Object
- #forward! ⇒ Object
-
#initialize(*a) ⇒ History
constructor
A new instance of History.
- #last! ⇒ Object
Methods inherited from Array
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
#position ⇒ Object
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 |
#back ⇒ Object
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 |
#forward ⇒ Object
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 |