From: Kev Jackson Date: 2006-03-30T17:46:27+09:00 Subject: Re: accessing the currently running method > > There is binding_of_caller which might or might not help you - > depending on what you want to do. > I'll look into it thanks > Another option is to use set_trace_func to set up something that keeps > track of method invocations. > >> No biggy, just interested if anyone else has ever wanted/needed to >> get this info in a running program, and what they did to do it > > > Certainly, from time to time. What do *you* need it for? I currently have a yaml file pg_401: corp_nm_kn: 'JP text...' <= corprate name (kana) etc and a ruby script that uses watir to execute a set of web app page transitions whilst filling in the data read from the yaml file. in standard watir ie.text_field(:id, 'some id value for text field').set(v) as I'm reading the data from a yaml file I get a hash of hashes (ok I could get an object or anything else, but at the moment I get back a hash of hashes) so my calls to watir look like ie.text_field(:id, test_data['pg_401']['corp_name_field']).set(test_data['pg_401']['corp_name'] I've managed to reduce this to text :id, :pg_401, :corp_name which is expanded to the correct call using method_missing, I'd like to reduce this further to text :corp_name I can remove the :pg_401 by knowing the currently executing method, I can remove the :id by simply trying all options :id, :name, :matches (I think) and rescuing the Exception raised. Ultimately, I'd rather have all these field_type, :field_name pairs defined in yaml and then create a script on the fly and execute it. At the moment, the qc team will have to edit two files (data in yaml format, and script in ruby). Why would I want to reduce the amount of text typed by the qc team (who will be writing these scripts)?: 1 - because it's possible to reduce the workload 2 - because some of the screens (pg_XXX) have more than 400 fields that must be entered (not my fault, I had no hand in designing the UI, for that you can blaim HP japan) 3 - because I'm starting to get why people think that DSLs and lisp macros are a good thing (I think I reached the tipping point of understanding, when I saw loads of my first calls to the watir library and thought, "That's irritatingly repetitive, surely the computer can do that kind of work for me"). Currently I have caller[0][/in: `.+(pg_\d{3})/,1] which adequately returns the current method (given the current convention of naming the methods something with the page number in them) I tried class Object def current_method caller[0][/in: `.+(pg_\d{3})/,1] end end but calls to this inside a method_missing method produce nil - not sure why, but obviously I need to study more ruby to understand why that doesn't work. Including current_method (as defined above) in module Kernel also doesn't do the trick, but having the caller[0][/in: `.+(pg_\d{3})/,1] inside the method_missing method works. Thanks for pointing me in the direction of a couple of new things Kev