Class: EhbGameLib::Utils::Cursor
- Inherits:
-
Object
- Object
- EhbGameLib::Utils::Cursor
- Defined in:
- lib/ehb_game_lib/utils/cursor.rb
Instance Method Summary collapse
- #current ⇒ Object
- #index ⇒ Object
-
#initialize(set) ⇒ Cursor
constructor
A new instance of Cursor.
- #next_element ⇒ Object
- #previous_element ⇒ Object
- #select_last ⇒ Object
Constructor Details
#initialize(set) ⇒ Cursor
Returns a new instance of Cursor.
6 7 8 9 |
# File 'lib/ehb_game_lib/utils/cursor.rb', line 6 def initialize(set) @set = set.to_a @index = nil end |
Instance Method Details
#current ⇒ Object
25 26 27 |
# File 'lib/ehb_game_lib/utils/cursor.rb', line 25 def current index.nil? ? nil : @set[index] end |
#index ⇒ Object
29 30 31 32 |
# File 'lib/ehb_game_lib/utils/cursor.rb', line 29 def index fix_index @index end |
#next_element ⇒ Object
17 18 19 |
# File 'lib/ehb_game_lib/utils/cursor.rb', line 17 def next_element next_previous_element(1) end |
#previous_element ⇒ Object
21 22 23 |
# File 'lib/ehb_game_lib/utils/cursor.rb', line 21 def previous_element next_previous_element(-1) end |
#select_last ⇒ Object
13 14 15 |
# File 'lib/ehb_game_lib/utils/cursor.rb', line 13 def select_last self.index = @set.length - 1 end |