From: Thomas Mueller Date: 2008-03-05T09:56:21+09:00 Subject: Re: Inspecting a block given to a method Thanks for your quick reply. If I understand you correctly that would result in something like this being executed: bc.find_all(search_specs) do |record| activate("field1") # this is what the proxy object would do record["field1"] = "some value" activate("field2") # this is what the proxy object would do puts record["field2"] end That wouldn't work because the fields need to be activated before I query the data, basically before or at the beginning of the find_all() method. When I query for data in Siebel it issues SQL statements to the database and only includes activated fields. Activating fields just before accessing them doesn't work - they need to be activated before querying the database. My find_all() looks something like this: def find_all self.clear_to_query() self.set_search_spec(...) # several of those, based on arguments to find_all() self.execute_query() begin yield self end while self.next_record() if self.first_record() end The fields need to be activated before the execute_query() call. Thomas 2008/3/5, Christopher Dicely : > On Tue, Mar 4, 2008 at 3:00 PM, Thomas Mueller > wrote: > > Hi, > > > > I am using JRuby to access data in some business application (Siebel, > > if anybody is interested). > > In Siebel I need to activate fields if I want to access them later: > > > > bc.activate_field(name) > > bc.query(search_specs) > > do stuff > > > > I've written methods that do the query and then yield each record to a > > given block, so I can write something like: > > > > bc.activate_field("field1") > > bc.activate_field("field2") > > bc.find_all(search_specs) do |record| > > record["field1"] = "some value" > > puts record["field2"] > > end > > > > I would like to do the activate_field() calls automatically, based on > > which fields are being accessed inside the block. > > Is it possible to look into the block and find out which fields are > > being accessed? In the above example that would include the fields > > "field1" and "field2". > > Basically, can I access the code inside the block and inspect it? > > > > I don't know of any way to do that. But I don't think you need to: > you can yield a proxy object to the block that intercepts the > references (the []= methods on the record object, or anything else > that requires activation) and activates fields as necessary, before > passing the call on to the object that does the real work, I think. > >