Class: Reline::History

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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ History

Returns a new instance of History.



2
3
4
# File 'lib/reline/history.rb', line 2

def initialize(config)
  @config = config
end

Instance Method Details

#<<(val) ⇒ Object



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

def <<(val)
  shift if size + 1 > @config.history_size
  super(String.new(val, encoding: Reline.encoding_system_needs))
end

#[](index) ⇒ Object



15
16
17
18
# File 'lib/reline/history.rb', line 15

def [](index)
  index = check_index(index) unless index.is_a?(Range)
  super(index)
end

#[]=(index, val) ⇒ Object



20
21
22
23
# File 'lib/reline/history.rb', line 20

def []=(index, val)
  index = check_index(index)
  super(index, String.new(val, encoding: Reline.encoding_system_needs))
end

#concat(*val) ⇒ Object



25
26
27
28
29
# File 'lib/reline/history.rb', line 25

def concat(*val)
  val.each do |v|
    push(*v)
  end
end

#delete_at(index) ⇒ Object



10
11
12
13
# File 'lib/reline/history.rb', line 10

def delete_at(index)
  index = check_index(index)
  super(index)
end

#push(*val) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/reline/history.rb', line 31

def push(*val)
  diff = size + val.size - @config.history_size
  if diff > 0
    if diff <= size
      shift(diff)
    else
      diff -= size
      clear
      val.shift(diff)
    end
  end
  super(*(val.map{ |v| String.new(v, encoding: Reline.encoding_system_needs) }))
end

#to_sObject



6
7
8
# File 'lib/reline/history.rb', line 6

def to_s
  'HISTORY'
end