From: SASADA Koichi Date: 2012-09-21T10:14:34+09:00 Subject: [ruby-core:47627] Re: ObjectSpace.reference_form(obj) #=> references_array Revisit. I made a patch: https://github.com/ko1/ruby/tree/all_refs ObjectSpace.all_references_from(obj) #=> [...] I don't any strong idea about naming. - ObjectSpace.contains(obj) - ObjectSpace.reachable_set(obj) - ObjectSpace.transitive_closure(obj) "ObjectSpace.reachable_objects_from(obj)" is more descriptive? (2011/10/01 8:17), Tim Felgentreff wrote: > On 09/30/2011 07:08 AM, SASADA Koichi wrote: >> (2011/09/30 5:37), hemant wrote: >>> I think reference_from is a bit ambiguous as it stands. How about "contains" ? >> >> ObjectSpace.contains(obj) ? > > #reachable_set or #transitive_closure seem to be the names that are used > in graph theory papers. Maybe we should try stick to what's already there. > >> >>> I am not sure, what values are in the output though. Are they Type or >>> output of inspect? >> >> >> As I wrote in first post: >> >>> h = {'a' => [1, 2, 3], 'b' => Object.new} >>> p ObjectSpace.reference_from(h) >>> #=> >>> {76577650=>Hash, 76559320=>"a", 76559360=>[1, 2, 3], 76559310=>"b", >>> 76559340=>#} >>> >>> Hash keys are object id and values are objects themselves. >> >> Output is inspected string by "p". >> > > What are the opinions on adding an official mirror API to Ruby to > separate reflection from non-metalevel stuff and doing things like that > on mirrors in the future? Adding more functions to ObjectSpace et.al. > doesn't seem like good OO to me in the long run. How about having > > ObjectMirror.reflect_on(h).transitive_closure? > > or similar? There's a good paper by Gilad Bracha and David Ungar, > > "Mirrors: Design Principles for Meta-level Facilities of Object-Oriented > Programming Languages" > > that we could draw ideas from. > -- // SASADA Koichi at atdot dot net