class List
Attributes
items[R]
Public Class Methods
new(items = [])
click to toggle source
# File lib/list.rb, line 7 def initialize(items = []) @items = items end
Public Instance Methods
add(item)
click to toggle source
# File lib/list.rb, line 11 def add(item) raise 'Already exists in list' if found?(item) @items << item 'Success' end
find(item)
click to toggle source
# File lib/list.rb, line 35 def find(item) all.detect { |arr| arr == item } end
get_by_index(index)
click to toggle source
# File lib/list.rb, line 31 def get_by_index(index) all[index] end
remove(item)
click to toggle source
# File lib/list.rb, line 17 def remove(item) raise 'Not found in list' unless found?(item) @items.delete(item) 'Success' end
to_string(item_list_printer = ItemListPrinter)
click to toggle source
# File lib/list.rb, line 23 def to_string(item_list_printer = ItemListPrinter) item_list_printer.to_string(all) end
to_summary(keys, item_list_printer = ItemListPrinter)
click to toggle source
# File lib/list.rb, line 27 def to_summary(keys, item_list_printer = ItemListPrinter) item_list_printer.to_summary(all, keys) end
Private Instance Methods
all()
click to toggle source
# File lib/list.rb, line 45 def all @items end
found?(item)
click to toggle source
# File lib/list.rb, line 41 def found?(item) @items.include?(item) end