Class: ArgumentsParser

Inherits:
Object show all
Defined in:
lib/ruby_ext/prepare_arguments.rb

Class Method Summary collapse

Class Method Details

.parse_arguments_for(method, *args, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/ruby_ext/prepare_arguments.rb', line 13

def parse_arguments_for method, *args, &block
   = @registry[method]
  index = 0
  parsed_args = .collect do |options| 
    send options[:type], args, block, options, index, (index == .size - 1)
  end
  args.must_be.empty
  return parsed_args
end

.register(method, arguments) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/ruby_ext/prepare_arguments.rb', line 3

def register method, arguments
  # check and prepare metadata
  arguments.collect!{|meta| meta.is_a?(Hash) ? meta : {:type => meta}}
  arguments.each{|meta| meta.must.include :type}
  
  # register
  @registry ||= {}
  @registry[method] = arguments
end