Class: V::Arguments
- Inherits:
-
Object
- Object
- V::Arguments
- Defined in:
- lib/v/arguments.rb
Defined Under Namespace
Classes: Slot
Instance Method Summary collapse
- #%(args) ⇒ Object
- #<<(string) ⇒ Object
-
#initialize(op) {|_self| ... } ⇒ Arguments
constructor
A new instance of Arguments.
- #inspect ⇒ Object
- #method_missing(argument, *defaults) ⇒ Object
Constructor Details
#initialize(op) {|_self| ... } ⇒ Arguments
Returns a new instance of Arguments.
5 6 7 8 9 10 11 |
# File 'lib/v/arguments.rb', line 5 def initialize(op, &args) @op, @first_argument = op.to_sym, nil @slots = [] yield self if block_given? @slots.freeze end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
Instance Method Details
#%(args) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/v/arguments.rb', line 27 def %(args) opts = Hash === args.last ? args.pop : {} opts[@first_argument] = args.shift if @first_argument op_args = @slots.inject([@op]) { |ca, slot| if String === slot ca << slot elsif key = slot.key(opts) if slot.standalone? and opts[key] ca << slot else value = opts[key] if slot.defaults_to? value then ca else ca << slot.to_s % quote(value) end end else ca end }.concat args.map { |arg| quote arg } op_args * ' ' end |
#<<(string) ⇒ Object
23 24 25 |
# File 'lib/v/arguments.rb', line 23 def <<(string) @slots << string end |
#inspect ⇒ Object
53 54 55 |
# File 'lib/v/arguments.rb', line 53 def inspect @slots.inspect end |