Hi,
I wrote a patch of ObjectSpace.reference_form(obj). This method returns
references that this object has.
example:
require 'objspace'
h = {'a' => [1, 2, 3], 'b' => Object.new}
p ObjectSpace.reference_from(h)
#=>
{76577650=>Hash, 76559320=>"a", 76559360=>[1, 2, 3], 76559310=>"b",
76559340=>#<Object:0x92067d8>}
Hash keys are object id and values are objects themselves.
Patch:
http://www.atdot.net/sp/view/apl9sl/readonly
How about it? Good name is also welcome.
# Flight from Porland to New Orleans hack.
on 2011-09-29 05:31
on 2011-09-29 14:05
Hi, (11/09/29 12:30), SASADA Koichi wrote: > {76577650=>Hash, 76559320=>"a", 76559360=>[1, 2, 3], 76559310=>"b", > 76559340=>#<Object:0x92067d8>} > > Hash keys are object id and values are objects themselves. Why object id hash, but not a plain array?
on 2011-09-30 12:38
Hi, 2011/9/29 Nobuyoshi Nakada <nobu@ruby-lang.org>: > Hi, > > (11/09/29 12:30), SASADA Koichi wrote: >> {76577650=>Hash, 76559320=>"a", 76559360=>[1, 2, 3], 76559310=>"b", >> 76559340=>#<Object:0x92067d8>} >> >> Hash keys are object id and values are objects themselves. > > Why object id hash, but not a plain array? I think reference_from is a bit ambiguous as it stands. How about "contains" ? I am not sure, what values are in the output though. Are they Type or output of inspect? -- Let them talk of their oriental summer climes of everlasting conservatories; give me the privilege of making my own summer with my own coals. http://gnufied.org http://twitter.com/gnufied
on 2011-09-30 16:08
(2011/09/30 5:37), hemant wrote: > I think reference_from is a bit ambiguous as it stands. How about "contains" ? ObjectSpace.contains(obj) ? > 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=>#<Object:0x92067d8>} > > Hash keys are object id and values are objects themselves. Output is inspected string by "p".
on 2011-10-01 17:17
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. >> {76577650=>Hash, 76559320=>"a", 76559360=>[1, 2, 3], 76559310=>"b", >> 76559340=>#<Object:0x92067d8>} >> >> 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.
on 2012-09-21 03:15
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?
on 2012-09-25 00:39
On Sep 20, 2012, at 6:14 PM, SASADA Koichi <ko1@atdot.net> wrote: > - ObjectSpace.reachable_set(obj) > - ObjectSpace.transitive_closure(obj) > > "ObjectSpace.reachable_objects_from(obj)" is more descriptive? I think this name is the most descriptive.
on 2012-09-25 06:53
(2012/09/25 7:38), Eric Hodel wrote: >> > "ObjectSpace.reachable_objects_from(obj)" is more descriptive? > I think this name is the most descriptive. > Thanks. Matz, nari-san, can I apply this patch?
on 2012-09-25 08:19
I'm sorry for late reply. 2012/9/25 SASADA Koichi <ko1@atdot.net>: > (2012/09/25 7:38), Eric Hodel wrote: >>> > "ObjectSpace.reachable_objects_from(obj)" is more descriptive? >> I think this name is the most descriptive. >> Do you have any use cases? Nakada-san says: > Why object id hash, but not a plain array? How about it?
on 2012-09-25 08:26
(2012/09/25 15:18), Narihiro Nakamura wrote: > Do you have any use cases? Analysis. For example, find out memory leak. > Nakada-san says: >> > Why object id hash, but not a plain array? > How about it? The latest patch returns a plain array or nil.
on 2012-09-25 09:20
2012/9/25 SASADA Koichi <ko1@atdot.net>:
>
Ahh, I see.
Please commit it if matz accepts it.
Thanks.
on 2012-10-05 08:21
(2012/09/25 16:19), Narihiro Nakamura wrote:
> Please commit it if matz accepts it.
I got matz approval.
I'll commit `ObjectSpace.reachable_objects_from(obj)'.
Thanks,
Koichi
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.