Module: Arguments

Defined in:
lib/arguments.rb,
lib/arguments/vm.rb,
lib/arguments/mri.rb

Constant Summary collapse

VERSION =
'0.4.7'

Class Method Summary collapse

Class Method Details

.names(klass, method) ⇒ Object



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

def self.names klass, method
  source, line = klass.instance_method( method ).source_location rescue klass.method( method ).source_location
  return [] unless source and line
  str = IO.readlines(source)[ line - 1 ]
  return [] if str.match(/\*\w+/)
  throw 'poor comma' + str if str  =~ /,\W*&/
  str.match(/def\s*\w+\s*\(?\s*([^)\n]*)/)[1] #This could look better
    .scan(/(\w+)(?:\s*=\s*([^,]+))|(\w+)/).map{ |e| e.compact  }.collect{|e2| e2[1].gsub!(/\W*\&.*/, '') if e2[1]; e2}
end