Class: Menu
Overview
Shows options that the user can choose from. Options may be associated with sub-menus.
Defined Under Namespace
Classes: MenuError
Constant Summary collapse
- @@global_elements =
[]
[]
Constants included from BasicLogging
BasicLogging::DEBUG, BasicLogging::ERROR, BasicLogging::FATAL, BasicLogging::INFO, BasicLogging::Levels, BasicLogging::UNKNOWN, BasicLogging::WARN
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#name ⇒ Object
Returns the value of attribute name.
Attributes included from BasicLogging
Instance Method Summary collapse
- #add(element, pos = nil) ⇒ Object (also: #add_action, #add_sub_menu, #add_menu)
- #call(*args) ⇒ Object
-
#initialize(options = {}) ⇒ Menu
constructor
A new instance of Menu.
Methods included from BasicLogging
is_muted?, #log, mute, #set_level, set_level, set_target, #set_target
Constructor Details
#initialize(options = {}) ⇒ Menu
Returns a new instance of Menu.
36 37 38 39 40 41 42 43 |
# File 'lib/menu.rb', line 36 def initialize( = {}) @elements = [] if( && !.respond_to?(:to_hash) ) raise MenuError.new('Arguments to menu.new must be hash-pairs') end @name = [:name] if [:name] @key = [:key] if [:key] end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
87 88 89 |
# File 'lib/menu.rb', line 87 def key @key end |
#name ⇒ Object
Returns the value of attribute name.
87 88 89 |
# File 'lib/menu.rb', line 87 def name @name end |
Instance Method Details
#add(element, pos = nil) ⇒ Object Also known as: add_action, ,
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/menu.rb', line 49 def add(element, pos = nil) if(element.respond_to?(:call)) if(pos) @elements.insert(pos, element) else @elements << element end # make available the same element in any sub-menus. if(element.respond_to?(:global) && element.global) @@global_elements << element end # hidden elements if(element.respond_to?(:hidden) && element.hidden) @@hidden_elements << element end else raise MenuError("{#element.to_s} cannot be used as action or sub-menu: missing method 'call()'}") end end |
#call(*args) ⇒ Object
45 46 47 |
# File 'lib/menu.rb', line 45 def call(*args) show() end |