HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/rvm/src/ruby-3.0.2/spec/ruby/shared/kernel/object_id.rb
# These examples hold for both BasicObject#__id__ and Kernel#object_id.
describe :object_id, shared: true do
  it "returns an integer" do
    o1 = @object.new
    o1.__send__(@method).should be_kind_of(Integer)
  end

  it "returns the same value on all calls to id for a given object" do
    o1 = @object.new
    o1.__send__(@method).should == o1.__send__(@method)
  end

  it "returns different values for different objects" do
    o1 = @object.new
    o2 = @object.new
    o1.__send__(@method).should_not == o2.__send__(@method)
  end

  it "returns the same value for two Integers with the same value" do
    o1 = 1
    o2 = 1
    o1.send(@method).should == o2.send(@method)
  end

  it "returns the same value for two Symbol literals" do
    o1 = :hello
    o2 = :hello
    o1.send(@method).should == o2.send(@method)
  end

  it "returns the same value for two true literals" do
    o1 = true
    o2 = true
    o1.send(@method).should == o2.send(@method)
  end

  it "returns the same value for two false literals" do
    o1 = false
    o2 = false
    o1.send(@method).should == o2.send(@method)
  end

  it "returns the same value for two nil literals" do
    o1 = nil
    o2 = nil
    o1.send(@method).should == o2.send(@method)
  end

  it "returns a different value for two Integer literals" do
    o1 = 2e100.to_i
    o2 = 2e100.to_i
    o1.send(@method).should_not == o2.send(@method)
  end

  it "returns a different value for two String literals" do
    o1 = "hello"
    o2 = "hello"
    o1.send(@method).should_not == o2.send(@method)
  end

  it "returns a different value for an object and its dup" do
    o1 = mock("object")
    o2 = o1.dup
    o1.send(@method).should_not == o2.send(@method)
  end

  it "returns a different value for two numbers near the 32 bit Integer limit" do
    o1 = -1
    o2 = 2 ** 30 - 1

    o1.send(@method).should_not == o2.send(@method)
  end

  it "returns a different value for two numbers near the 64 bit Integer limit" do
    o1 = -1
    o2 = 2 ** 62 - 1

    o1.send(@method).should_not == o2.send(@method)
  end
end