class Rmk::Utility::Flags
set of flags, e.g., for a compiler
Attributes
list[R]
Public Class Methods
new(f = [])
click to toggle source
# File lib/utilities.rb, line 8 def initialize(f = []) @list = f.clone end
Public Instance Methods
<<(f)
click to toggle source
same as #add
# File lib/utilities.rb, line 39 def <<(f) add(f) end
add(f)
click to toggle source
#add flag(s)
# File lib/utilities.rb, line 27 def add(f) if f.respond_to?(:each) f.each { |ff| add(ff) } else if f.respond_to?(:call) f=f.call() end @list << f.to_s unless f.nil? || f.empty? end end
clear()
click to toggle source
#clear all
# File lib/utilities.rb, line 87 def clear @list.clear end
find(f)
click to toggle source
#find flag f (may be a
regex pattern)
# File lib/utilities.rb, line 54 def find(f) if f.is_a?(String) @list.find_all { |ff| ff == f } else @list.find_all { |ff| ff =~ f } end end
include?(f)
click to toggle source
test result of #find(f)
# File lib/utilities.rb, line 63 def include?(f) !find(f).empty? end
map!(&block)
click to toggle source
map all flags
# File lib/utilities.rb, line 68 def map!(&block) @list.map!(&block) end
map_pattern!(f) { |ff| ... }
click to toggle source
map all flags matching f, return number of matches
# File lib/utilities.rb, line 73 def map_pattern!(f) n = 0 @list.map! do |ff| if f.is_a?(String) ? (ff == f) : (ff =~ f) n += 1 yield(ff) else ff end end n end
pop()
click to toggle source
# File lib/utilities.rb, line 17 def pop @list = @stack.pop end
push()
click to toggle source
# File lib/utilities.rb, line 12 def push @stack ||= [] @stack << @list.dup end
remove(f)
click to toggle source
#remove flag f
# File lib/utilities.rb, line 44 def remove(f) # TODO: return removed @list = if f.is_a?(String) @list.find_all { |ff| ff != f } else @list.find_all { |ff| ff !~ f } end end
text()
click to toggle source
get flags as #text
# File lib/utilities.rb, line 92 def text @list.join(' ') end
to_s()
click to toggle source
same as #text
# File lib/utilities.rb, line 97 def to_s text end
top()
click to toggle source
# File lib/utilities.rb, line 21 def top return nil if @stack&.empty? @stack[-1] end