Class: Ruber::OutputWidget::ActionList
- Inherits:
- Array show all
- Defined in:
- lib/ruber/output_widget.rb,
lib/ruber/output_widget.rb,
lib/ruber/output_widget.rb,
lib/ruber/output_widget.rb,
lib/ruber/output_widget.rb
Overview
Array of actions and separators (represented by nil) which allows to easily insert an entry before or after another one
Instance Method Summary (collapse)
-
- (self) insert_after(entry, *names)
Inserts one or more actions after a given one.
-
- (self) insert_after_or_before(entry, where, names)
private
Helper method used by #insert_after and #insert_before.
-
- (self) insert_before(entry, *names)
Inserts one or more actions before a given one.
Methods inherited from Array
#only?, #sample, #to_array, #to_h
Instance Method Details
- (self) insert_after(entry, *names)
Inserts one or more actions after a given one
1185 1186 1187 |
# File 'lib/ruber/output_widget.rb', line 1185 def insert_after entry, *names insert_after_or_before entry, :after, names end |
- (self) insert_after_or_before(entry, where, names) (private)
Helper method used by #insert_after and #insert_before
This is the method which performs the actual insertion of elements
1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 |
# File 'lib/ruber/output_widget.rb', line 1202 def insert_after_or_before entry, where, names idx = if entry.is_a? Integer # The - 1 is needed because entry is the number of separators, but indexes start # at 0 (self.each_with_index.find_all{|a, i| a.nil?}[entry - 1] || [])[1] else self.index(entry) end if idx and where == :after then idx += 1 elsif !idx then idx = size end #Using reverse_each, we don't need to care increasing idx as we add items (the #first item should be at position idx, the second at idx+1 and so on. With reverse_each) #this happens automatically. The +1 is needed to insert the items after idx names.reverse_each{|n| insert idx, n} self end |
- (self) insert_before(entry, *names)
Inserts one or more actions before a given one
1169 1170 1171 |
# File 'lib/ruber/output_widget.rb', line 1169 def insert_before entry, *names insert_after_or_before entry, :before, names end |