Class: Mmmenu::Level

Inherits:
Object
  • Object
show all
Defined in:
lib/mmmenu/level.rb

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Level

Returns a new instance of Level.

Yields:

  • (_self)

Yield Parameters:

  • _self (Mmmenu::Level)

    the object that the method was called on



5
6
7
8
# File 'lib/mmmenu/level.rb', line 5

def initialize(&block)
  @items = []
  yield(self)
end

Instance Method Details

#add(title, href, options = {}, &block) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/mmmenu/level.rb', line 10

def add(title, href, options={}, &block)
  children = {}
  if block_given? # which means current item has children
    children = { :children => self.class.new(&block).to_a }
  end
  @items << { :title => title, :href => href }.merge(options).merge(children)
end

#to_aObject



18
19
20
# File 'lib/mmmenu/level.rb', line 18

def to_a
  @items
end