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.
4 5 6 7 |
# File 'lib/ehb_game_lib/utils/cursor.rb', line 4 def initialize(set) @set = set.to_a @index = nil end |
Instance Method Details
#current ⇒ Object
23 24 25 |
# File 'lib/ehb_game_lib/utils/cursor.rb', line 23 def current index.nil? ? nil : @set[index] end |
#index ⇒ Object
27 28 29 30 |
# File 'lib/ehb_game_lib/utils/cursor.rb', line 27 def index fix_index @index end |
#next_element ⇒ Object
15 16 17 |
# File 'lib/ehb_game_lib/utils/cursor.rb', line 15 def next_element next_previous_element(1) end |
#previous_element ⇒ Object
19 20 21 |
# File 'lib/ehb_game_lib/utils/cursor.rb', line 19 def previous_element next_previous_element(-1) end |
#select_last ⇒ Object
11 12 13 |
# File 'lib/ehb_game_lib/utils/cursor.rb', line 11 def select_last self.index = @set.length - 1 end |