Skip to content

Commit

Permalink
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/object_space.rb
Original file line number Diff line number Diff line change
@@ -6,11 +6,12 @@ def self.find_object(query, callable)

def self._id2ref(id)
ary = []

if find_object([:object_id, Integer(id)], ary) > 0
return ary.first
end

return nil
raise RangeError, "#{id} is not a valid ID value"
end

def self.find_references(obj)
4 changes: 4 additions & 0 deletions spec/ruby/core/objectspace/_id2ref_spec.rb
Original file line number Diff line number Diff line change
@@ -18,4 +18,8 @@
r = ObjectSpace._id2ref(s.object_id)
r.should == s
end

it 'raises RangeError when an object could not be found' do
proc { ObjectSpace._id2ref(1 << 60) }.should raise_error(RangeError)
end
end

0 comments on commit 89cf641

Please sign in to comment.