Class: RubyCurses::MenuTree

Inherits:
Object
  • Object
show all
Defined in:
lib/rbcurse/extras/widgets/menutree.rb

Overview

Create a simple tree-ish structure. Each node is not a tree, only submenus are trees Others contain a hash with menu character and code Typically the code is not a method symbol, it is to be used to decode a description or method symbol from anoterh hash

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, hash = {}) ⇒ MenuTree

Returns a new instance of MenuTree.



20
21
22
# File 'lib/rbcurse/extras/widgets/menutree.rb', line 20

def initialize value, hash = {}
  @value = [value, hash]
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



19
20
21
# File 'lib/rbcurse/extras/widgets/menutree.rb', line 19

def value
  @value
end

Instance Method Details

#<<(kv) ⇒ Object



23
24
25
# File 'lib/rbcurse/extras/widgets/menutree.rb', line 23

def << kv
  @value[1][kv[0]] = kv[1]
end

#[](x) ⇒ Object



33
34
35
# File 'lib/rbcurse/extras/widgets/menutree.rb', line 33

def [](x)
  hash()[x]
end

#[]=(x, y) ⇒ Object



36
37
38
# File 'lib/rbcurse/extras/widgets/menutree.rb', line 36

def []=(x,y)
  hash()[x] = y
end

#eachObject



44
45
46
# File 'lib/rbcurse/extras/widgets/menutree.rb', line 44

def each
  hash().keys.each { |e| yield e }
end

#each_pairObject



47
48
49
# File 'lib/rbcurse/extras/widgets/menutree.rb', line 47

def each_pair
  hash().each_pair { |name, val| yield name, val  }
end

#hashObject Also known as: children



26
27
28
# File 'lib/rbcurse/extras/widgets/menutree.rb', line 26

def hash
  @value[1]
end

#push(hsh) ⇒ Object



30
31
32
# File 'lib/rbcurse/extras/widgets/menutree.rb', line 30

def push hsh
  hash().merge hsh
end


39
40
41
42
43
# File 'lib/rbcurse/extras/widgets/menutree.rb', line 39

def submenu key, value, hash = {}
  m = MenuTree.new value, hash
  #hash()[key] = [value, hash]
  hash()[key] = m
end