From: Tobias Reif Date: 2002-01-28T07:10:39+09:00 Subject: Re: how to find out which args a method can take Mathieu Bouchard wrote: > On Mon, 28 Jan 2002, Tobias Reif wrote: > >>how can I programmatically find out which objects a certain method can >>take if any? >> > Congratulations, you just ran into the invisible wall called "paradigm", > or, in other words, a shared delusion based on a reductionist philosophy. I know that I can pass wide varieties to some methods. What I thought was: perhaps there are any built-in documentation like info bits that can help whan generating "tests" for built-in methiods. Something like Array.works_with_args?('join') # -> [[String]] String.works_with_args('sub') # -> [[Regex,String], [Regex, Block]] String.works_with_args('reverse') # -> [] ((which) do other languages provide such stuff to programs?) So I could --- # generate something like # http://www.pinkjuice.com/txt/methReturnType.rb # for all built-in classes class_names = ['String'] #'Array','','','','','','','','' main_out = [] def make_line obj_name, method "puts \"#{method}:\\n \#\{#{obj_name}.#{method}('foo').type\}\"\n" end def make_class_tests name out = [] out.push = "# generated!\n" obj_name = name[0,1].downcase out.push obj_name+' = '+name+'.new(\'foo\')'+"\n" eval(name).new('foo').methods.sort.each do |method| out.push make_line(obj_name, method) end out #.split "\n" end class_names.each do |name| main_out.push make_class_tests(name) end puts main_out open ('array_return_types.rb', 'w') do |file| file.write main_out #.split("\n") end --- which generates ... puts "to_a:\n #{s.to_a('foo').type}" puts "to_f:\n #{s.to_f('foo').type}" puts "to_i:\n #{s.to_i('foo').type}" ... Anyways; sunday's over :) Tobi -- http://www.pinkjuice.com/