--Apple-Mail-9--551353325 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset -ascii On Nov 15, 2011, at 5:17 AM, Sophie wrote: > I want to build a Ruby app with the following broad properties > > - Has some graph of objects, with a root R > - each object (including R) has some methods, m > - each m on each object has some args A > - each A has a set of valid candidates values, defined by method candidates_A_m > - the objects have (string) names > > I want to build a command-line interface which lets me > > - start at the root R > - invoke methods by typing in a prefix and using TAB > - choose arg values by typing in object-name prefix and TAB > - getting autocompletion or suggestion-list whenever possible > - change my "working" location in the graph (like "cd") & continue > > I have not used Ruby in some time. Am looking for any suggestions on useful classes / libraries / methods / apps I should consider to make my life easier :-) > > Thanks! > > > Hi Sophie, What would the relation between the objects be ? Named relations ? You could use an OpenStruct or a hash to hold the related objects and then iterate through that list as you press tab. The hash key would be the object name string you indicated in your email. Once on a object if you want to retrieve the public methods you can: object.public_methods which returns you an array with the method symbols so you can iterate through it. Once on a method you can find out the arity of it with "method.arity" and find out the name of the parameters and if it is requiered with "method.parameters" and call it with "method.call" e.g. From the pick axe: def m(a, b=1, *c, &d) end method(:m).parameters # => [[:req, :a], [:opt, :b], [:rest, :c], [:block, :d]] I would not try to replicate that functionality as luckily Ruby provides us with great reflection methods. Regards, V. --Apple-Mail-9--551353325--