ruby/spec/rubyspec/core/objectspace/fixtures/classes.rb
eregon 95e8c48dd3 Add in-tree mspec and ruby/spec
* For easier modifications of ruby/spec by MRI developers.
* .gitignore: track changes under spec.
* spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec.
  These files can therefore be updated like any other file in MRI.
  Instructions are provided in spec/README.
  [Feature #13156] [ruby-core:79246]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-07 12:04:49 +00:00

64 lines
1.2 KiB
Ruby

module ObjectSpaceFixtures
def self.garbage
blah
end
def self.blah
o = "hello"
@garbage_objid = o.object_id
return o
end
@last_objid = nil
def self.last_objid
@last_objid
end
def self.garbage_objid
@garbage_objid
end
def self.make_finalizer
proc { |obj_id| @last_objid = obj_id }
end
def self.define_finalizer
handler = lambda { |obj| ScratchPad.record :finalized }
ObjectSpace.define_finalizer "#{rand 5}", handler
end
def self.scoped(wr)
return Proc.new { wr.write "finalized"; wr.close }
end
class ObjectToBeFound
attr_reader :name
def initialize(name)
@name = name
end
end
class ObjectWithInstanceVariable
def initialize
@instance_variable = ObjectToBeFound.new(:instance_variable)
end
end
def self.to_be_found_symbols
ObjectSpace.each_object(ObjectToBeFound).map do |o|
o.name
end
end
o = ObjectToBeFound.new(:captured_by_define_method)
define_method :capturing_method do
o
end
SECOND_LEVEL_CONSTANT = ObjectToBeFound.new(:second_level_constant)
end
OBJECT_SPACE_TOP_LEVEL_CONSTANT = ObjectSpaceFixtures::ObjectToBeFound.new(:top_level_constant)