Class: Rake::TaskArguments

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/rake.rb

Overview

TaskAguments manage the arguments passed to a task.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Enumerable

#to_set

Constructor Details

- (TaskArguments) initialize(names, values, parent = nil)

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.



339
340
341
342
343
344
345
346
# File 'lib/rake.rb', line 339

def initialize(names, values, parent=nil)
  @names = names
  @parent = parent
  @hash = {}
  names.each_with_index { |name, i|
    @hash[name.to_sym] = values[i] unless values[i].nil?
  }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(sym, *args, &block)



371
372
373
# File 'lib/rake.rb', line 371

def method_missing(sym, *args, &block)
  lookup(sym.to_sym)
end

Instance Attribute Details

- (Object) names (readonly)

Returns the value of attribute names



334
335
336
# File 'lib/rake.rb', line 334

def names
  @names
end

Instance Method Details

- (Object) [](index)

Find an argument value by name or index.



356
357
358
# File 'lib/rake.rb', line 356

def [](index)
  lookup(index.to_sym)
end

- (Object) each(&block)



367
368
369
# File 'lib/rake.rb', line 367

def each(&block)
  @hash.each(&block)
end

- (Object) inspect



383
384
385
# File 'lib/rake.rb', line 383

def inspect
  to_s
end

- (Object) new_scope(names)

Create a new argument scope using the prerequisite argument names.



350
351
352
353
# File 'lib/rake.rb', line 350

def new_scope(names)
  values = names.collect { |n| self[n] }
  self.class.new(names, values, self)
end

- (Object) to_hash



375
376
377
# File 'lib/rake.rb', line 375

def to_hash
  @hash
end

- (Object) to_s



379
380
381
# File 'lib/rake.rb', line 379

def to_s
  @hash.inspect
end

- (Object) with_defaults(defaults)

Specify a hash of default values for task arguments. Use the defaults only if there is no specific value for the given argument.



363
364
365
# File 'lib/rake.rb', line 363

def with_defaults(defaults)
  @hash = defaults.merge(@hash)
end