lib/rprogram/option.rb in rprogram-0.1.0 vs lib/rprogram/option.rb in rprogram-0.1.1
- old
+ new
@@ -8,10 +8,13 @@
attr_reader :equals
# Can the option be specified multiple times
attr_reader :multiple
+ # Argument separator
+ attr_reader :separator
+
#
# Creates a new Option object with the specified _options_. If a _block_
# is given it will be used for the custom formating of the option. If a
# _block_ is not given, the option will use the default_format when
# generating the arguments.
@@ -20,16 +23,20 @@
# <tt>:flag</tt>:: The command-line flag to use.
# <tt>:equals</tt>:: Implies the option maybe formated as '--flag=value'.
# Defaults to +falue+, if not given.
# <tt>:multuple</tt>:: Implies the option maybe given an Array of
# values. Defaults to +false+, if not given.
+ # <tt>:separator</tt>:: The separator to use for formating multiple
+ # arguments into one +String+. Cannot be used
+ # with +:multiple+.
#
def initialize(options={},&block)
@flag = options[:flag]
@equals = options[:equals] || false
@multiple = options[:multiple] || false
+ @separator = options[:separator]
@formating = block
end
#
@@ -50,9 +57,13 @@
args = []
value.each { |arg| args += format(arg) }
return args
else
+ if (value.kind_of?(Array) && @separator)
+ value = value.join(@separator)
+ end
+
return format(value)
end
end
protected