Class: TTY::MenuTree::Action
- Inherits:
-
Object
- Object
- TTY::MenuTree::Action
- Defined in:
- lib/tty/menu_tree/action.rb
Overview
Base class for anything that can appear in a menu.
An action is any object that responds to the four methods below. You do
not have to subclass Action; duck typing is enough. Subclassing simply
gives you sensible defaults (#submenu => nil, #exit? => false) and
NotImplementedError guards for the parts you must define.
Direct Known Subclasses
Instance Method Summary collapse
-
#call ⇒ void
Invoked when a leaf action is selected.
-
#exit? ⇒ Boolean
When
true, selecting this action ends the top-level menu loop. -
#name ⇒ String
The label shown for this action in a menu.
-
#submenu ⇒ Array<#name>?
Child actions to descend into, or
nilfor a leaf action.
Instance Method Details
#call ⇒ void
This method returns an undefined value.
Invoked when a leaf action is selected.
Not called for actions that return a #submenu; those are descended into instead.
29 30 31 |
# File 'lib/tty/menu_tree/action.rb', line 29 def call raise NotImplementedError, "#{self.class}#call must be implemented" end |
#exit? ⇒ Boolean
Returns when true, selecting this action ends the top-level
menu loop.
41 42 43 |
# File 'lib/tty/menu_tree/action.rb', line 41 def exit? false end |
#name ⇒ String
Returns the label shown for this action in a menu.
19 20 21 |
# File 'lib/tty/menu_tree/action.rb', line 19 def name raise NotImplementedError, "#{self.class}#name must be implemented" end |
#submenu ⇒ Array<#name>?
Returns child actions to descend into, or nil for
a leaf action.
35 36 37 |
# File 'lib/tty/menu_tree/action.rb', line 35 def nil end |