Class: Docket::RobinList
- Inherits:
-
Object
- Object
- Docket::RobinList
- Defined in:
- lib/docket/robin_list.rb
Instance Method Summary collapse
- #fetch_after(e) ⇒ Object
- #fetch_before(e) ⇒ Object
- #fetch_next(index = 0) ⇒ Object
- #fetch_previous(index = 0) ⇒ Object
-
#initialize(array) ⇒ RobinList
constructor
A new instance of RobinList.
- #list ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(array) ⇒ RobinList
Returns a new instance of RobinList.
5 6 7 |
# File 'lib/docket/robin_list.rb', line 5 def initialize(array) @array = array end |
Instance Method Details
#fetch_after(e) ⇒ Object
25 26 27 |
# File 'lib/docket/robin_list.rb', line 25 def fetch_after(e) fetch_next(@array.index(e)) end |
#fetch_before(e) ⇒ Object
29 30 31 |
# File 'lib/docket/robin_list.rb', line 29 def fetch_before(e) fetch_previous(@array.index(e)) end |
#fetch_next(index = 0) ⇒ Object
21 22 23 |
# File 'lib/docket/robin_list.rb', line 21 def fetch_next(index=0) index.nil? ? nil : @array.push(@array.shift)[index] end |
#fetch_previous(index = 0) ⇒ Object
17 18 19 |
# File 'lib/docket/robin_list.rb', line 17 def fetch_previous(index=0) index.nil? ? nil : @array.unshift(@array.pop)[index] end |
#list ⇒ Object
13 14 15 |
# File 'lib/docket/robin_list.rb', line 13 def list @array end |
#size ⇒ Object
9 10 11 |
# File 'lib/docket/robin_list.rb', line 9 def size @array.size end |