class Raph::Parser::FlagParser
Considers option as flag if and only if it’s name starts with one dash and follows by one word character or starts with two dashes and follows by 2 or more word chacters or dashes.
Assumes that each option doesn’t have spaces.
Example of flags:
'-h' '-T' '--config'
Example of non-flags:
'option' '---option2' '--h'
Public Instance Methods
flag?(option)
click to toggle source
# File lib/raph/parser/flag_parser.rb, line 26 def flag?(option) !!(option =~ /^-[\w]$/ || option =~ /^--[\w][\w-]+$/) end
parse(args)
click to toggle source
# File lib/raph/parser/flag_parser.rb, line 18 def parse(args) flags = [] args.each do |a| flags << to_underscored_sym(a) if flag? a end flags end