TaskAguments manage the arguments passed to a task.
[],
each,
inspect,
lookup,
method_missing,
new,
new_scope,
to_hash,
to_s,
with_defaults,
Included modules
Enumerable
Create a TaskArgument object with a list of named arguments (given by
:names) and a set of associated values (given by :values). :parent is the
parent argument object.
322: def initialize(names, values, parent=nil)
323: @names = names
324: @parent = parent
325: @hash = {}
326: names.each_with_index { |name, i|
327: @hash[name.to_sym] = values[i] unless values[i].nil?
328: }
329: end
Find an argument value by name or index.
339: def [](index)
340: lookup(index.to_sym)
341: end
350: def each(&block)
351: @hash.each(&block)
352: end
366: def inspect
367: to_s
368: end
354: def method_missing(sym, *args, &block)
355: lookup(sym.to_sym)
356: end
Create a new argument scope using the prerequisite argument names.
333: def new_scope(names)
334: values = names.collect { |n| self[n] }
335: self.class.new(names, values, self)
336: end
358: def to_hash
359: @hash
360: end
362: def to_s
363: @hash.inspect
364: end
Specify a hash of default values for task arguments. Use the defaults only
if there is no specific value for the given argument.
346: def with_defaults(defaults)
347: @hash = defaults.merge(@hash)
348: end
Protected Instance methods |
372: def lookup(name)
373: if @hash.has_key?(name)
374: @hash[name]
375: elsif ENV.has_key?(name.to_s)
376: ENV[name.to_s]
377: elsif ENV.has_key?(name.to_s.upcase)
378: ENV[name.to_s.upcase]
379: elsif @parent
380: @parent.lookup(name)
381: end
382: end