Class: TTY::MenuTree::Group

Inherits:
Action
  • Object
show all
Defined in:
lib/tty/menu_tree/group.rb

Overview

An action that, when selected, opens a submenu of child actions rather than performing work itself.

Examples:

TTY::MenuTree::Group.new(name: "Settings", actions: [ChangeTheme.new, Reset.new])

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Action

#call, #exit?

Constructor Details

#initialize(name:, actions:) ⇒ Group

Returns a new instance of Group.

Parameters:

  • name (String) —

    label shown in the parent menu.

  • actions (Array<#name>) —

    child actions to show when this group is selected.



22
23
24
25
26
# File 'lib/tty/menu_tree/group.rb', line 22

def initialize(name:, actions:)
  super()
  @name = name
  @submenu = actions
end

Instance Attribute Details

#name ⇒ String (readonly)

Returns the label shown for this group.

Returns:

  • (String) —

    the label shown for this group.



14
15
16
# File 'lib/tty/menu_tree/group.rb', line 14

def name
  @name
end

Returns the child actions.

Returns:

  • (Array<#name>) —

    the child actions.



17
18
19
# File 'lib/tty/menu_tree/group.rb', line 17

def submenu
  @submenu
end