Class: SeedList::List
- Inherits:
-
Object
- Object
- SeedList::List
- Defined in:
- lib/seed_list/list.rb
Instance Method Summary collapse
- #delete(s) ⇒ Object
- #find(s) ⇒ Object
-
#initialize(*seeds) ⇒ List
constructor
A new instance of List.
- #move(s, i) ⇒ Object
- #push(s) ⇒ Object
- #unshift(s) ⇒ Object
Constructor Details
#initialize(*seeds) ⇒ List
Returns a new instance of List.
3 4 5 |
# File 'lib/seed_list/list.rb', line 3 def initialize(*seeds) @list = Array.new(seeds) end |
Instance Method Details
#delete(s) ⇒ Object
25 26 27 28 |
# File 'lib/seed_list/list.rb', line 25 def delete(s) @list.delete_if { |e| e == s } self end |
#find(s) ⇒ Object
30 31 32 33 |
# File 'lib/seed_list/list.rb', line 30 def find(s) i = @list.index(s) i.nil? ? nil : i + 1 end |
#move(s, i) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/seed_list/list.rb', line 7 def move(s, i) i -= 1 index = @list.index s @list.delete_at index if index < i @list.insert(i, s).uniq! self end |
#push(s) ⇒ Object
20 21 22 23 |
# File 'lib/seed_list/list.rb', line 20 def push(s) @list.push(s).uniq! self end |
#unshift(s) ⇒ Object
15 16 17 18 |
# File 'lib/seed_list/list.rb', line 15 def unshift(s) @list.unshift(s).uniq! self end |