Class: RailsMenu::Set

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_menu/set.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = 'default', element_list = []) ⇒ Set

Returns a new instance of Set.



16
17
18
19
20
21
22
# File 'lib/rails_menu/set.rb', line 16

def initialize(name = 'default', element_list = [])
  @name = name
  @element_list = []
  element_list.each{ |elem| self.add(*elem) }

  self.class.list[name] = self
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



14
15
16
# File 'lib/rails_menu/set.rb', line 14

def name
  @name
end

Class Method Details

.[](list_name) ⇒ Object



9
10
11
# File 'lib/rails_menu/set.rb', line 9

def [](list_name)
  list[list_name]
end

.listObject



5
6
7
# File 'lib/rails_menu/set.rb', line 5

def list
  @list ||= {}
end

Instance Method Details

#add(id, url = '', options = {}) ⇒ Object



24
25
26
27
28
# File 'lib/rails_menu/set.rb', line 24

def add(id, url = '', options = {})
  element = Element.new(id.to_s, url, options)
  @element_list << element
  element
end

#elementsObject



30
31
32
# File 'lib/rails_menu/set.rb', line 30

def elements
  @element_list
end