From: Steve Tu Date: 2013-02-01T22:17:36+09:00 Subject: Re: Novice: self, @self.respond_to? and dynamically built methods Joel Pearson wrote in post #1094736: > Have you tried self.methods.include? Joel, Just tried, but no joy. BUT... I tried adding the full method footprint into the self.respond_to? and that then seemed to work - seemed being the operative word, as I looked more at respond_to? and I read that the second argument is a flag for checking private methods. So, that implies that somehow, my 'local' methods have been classed as private? I can't see a private statement in my code at all - are methods in 'main' then classed as private by default? That also then made me think whether what I'm trying to achieve (all be it in learning mode) is possible. If respond_to? only checks if that method name is valid for the given object, I still have the problem of knowing what the method's footprint is. In my case, I have a whole series of tutorial modules - mainly called foo_test (ie array_test, hash_test, range_test...etc) - which can then optionally take arguments - ie in my hash_test, there may be umpteen sub-subjects - each being triggered by the option passed (ie hash_test(1) will show me blah, hash_test(2)...) So what I was after was dynamically building foo_test from the command line argument(s) and then calling the method, with or without arguments. But if respond_to? doesn't check the footprint, I still end up with a crash. Given that, is a better practice to simply call the method with and without the arguments, catching any error and simply not bothering to see if the object responds to that method? -- Posted via http://www.ruby-forum.com/.