From: Josh Cheek Date: 2011-08-01T08:15:46+09:00 Subject: Re: system stack error in ObjectSpace.each_object --f46d043be13a721d5d04a965b11c Content-Type: text/plain; charset=ISO-8859-1 On Sun, Jul 31, 2011 at 4:29 PM, luke gruber wrote: > Hey guys, I'm just starting to mess around with metaprogramming in Ruby, > so I was just having a bit of fun and trying to make a script that would > allow for creating a 'leader' object in a class, and then when that > object is sent a message, all other objects of some subordinate class > would respond to the same message. > > So the script I wrote is here: > https://github.com/luke-gru/lemmings/blob/master/leader.rb > > On line 52, I ran into this issue: > > def get_other_objects(subord_class) > obj_ary = [] > ObjectSpace.each_object(subord_class) do |o| > obj_ary.push(o) unless o.leader # here > end > obj_ary > end > > If I don't have the 'unless o.leader' expression modifier, it pushes > like a million of the 'leader' objects and raises a SystemStackError. > > I have no idea why, and would really appreciate an answer. > > Thanks, > > -Luke > > -- > Posted via http://www.ruby-forum.com/. > > When I ran your script, I didn't get that error. I got this output: Test true # hey guys hey guys hey guys hey guys hey guys hey guys hey guys hey guys hey guys hey guys hey guys hey guys hey guys # jumps: 'look at me!' # jumps: 'Ahhhhhhhhh!' # jumps: 'Ahhhhhhhhh!' # jumps: 'Ahhhhhhhhh!' # jumps: 'Ahhhhhhhhh!' # jumps: 'Ahhhhhhhhh!' # jumps: 'Ahhhhhhhhh!' # jumps: 'Ahhhhhhhhh!' # jumps: 'Ahhhhhhhhh!' # jumps: 'Ahhhhhhhhh!' # jumps: 'Ahhhhhhhhh!' # jumps: 'Ahhhhhhhhh!' # jumps: 'Ahhhhhhhhh!' # jumps: 'Ahhhhhhhhh!' # # ouch ouch ouch ouch ouch ouch ouch ouch ouch ouch ouch ouch Typically, SystemStackError is due to recursing for too long, perhaps I have more memory than you, or perhaps the Ruby I'm using (1.9.2-p180) is less memory intensive than the one you're using. Anyway, it should give you a message with more information and a stack trace / line number that tells you where to begin looking. --f46d043be13a721d5d04a965b11c--