lib/boson/inspectors/argument_inspector.rb in boson-0.0.1 vs lib/boson/inspectors/argument_inspector.rb in boson-0.1.0

- old
+ new

@@ -4,11 +4,11 @@ module Boson::ArgumentInspector extend self # Returns same argument arrays as scrape_with_eval but argument defaults haven't been evaluated. def scrape_with_text(file_string, meth) tabspace = "[ \t]" - if match = /^#{tabspace}*def#{tabspace}+#{meth}#{tabspace}*($|\(?\s*([^\)]+)\s*\)?\s*$)/.match(file_string) + if match = /^#{tabspace}*def#{tabspace}+#{meth}\b#{tabspace}*($|\(?\s*([^\)]+)\s*\)?\s*$)/.match(file_string) (match.to_a[2] || '').split(/\s*,\s*/).map {|e| e.split(/\s*=\s*/)} end end # Max number of arguments extracted per method with scrape_with_eval @@ -18,11 +18,11 @@ # ====Examples: # def meth1(arg1, arg2='val', options={}) -> [['arg1'], ['arg2', 'val'], ['options', {}]] # def meth2(*args) -> [['*args']] def scrape_with_eval(meth, klass, object) unless %w[initialize].include?(meth.to_s) - return if class << object; private_instance_methods(true) end.include?(meth.to_s) + return if class << object; private_instance_methods(true).map {|e| e.to_s } end.include?(meth.to_s) end params, values, arity, num_args = trace_method_args(meth, klass, object) return if local_variables == params # nothing new found format_arguments(params, values, arity, num_args) rescue Exception @@ -38,12 +38,12 @@ params.inject([[], 0]) do |(a, i), x| if Array === values[i] [a << ["*#{x}"], i+1] else if arity < 0 && i >= arity.abs - 1 - [a << [x, values[i]], i + 1] + [a << [x.to_s, values[i]], i + 1] else - [a << [x], i+1] + [a << [x.to_s], i+1] end end end.first end \ No newline at end of file