Class: Warg::Console::History

Inherits:
Object
  • Object
show all
Defined in:
lib/warg.rb

Defined Under Namespace

Classes: Entry, FirstEntry

Instance Method Summary collapse

Constructor Details

#initializeHistory

Returns a new instance of History.



279
280
281
# File 'lib/warg.rb', line 279

def initialize
  @head = FirstEntry.new
end

Instance Method Details

#append(content, at: cursor_position) ⇒ Object



283
284
285
286
287
288
289
290
# File 'lib/warg.rb', line 283

def append(content, at: cursor_position)
  entry = Entry.new(content, at)

  entry.previous_entry = @head
  @head.next_entry     = entry

  @head = entry
end

#find_entry_for(content) ⇒ Object



292
293
294
295
296
297
298
299
300
# File 'lib/warg.rb', line 292

def find_entry_for(content)
  current_entry = @head

  until current_entry.previous_entry.nil? || current_entry.content == content
    current_entry = current_entry.previous_entry
  end

  current_entry
end

#inspectObject



302
303
304
# File 'lib/warg.rb', line 302

def inspect
  %{#<#{self.class.name} head=#{@head}>}
end