1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/spec/ruby/core/hash/fixtures/classes.rb
eregon 4fbb9aa3cb Update to ruby/spec@6f38a82
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-28 19:50:06 +00:00

75 lines
1.1 KiB
Ruby

module HashSpecs
class MyHash < Hash; end
class MyInitializerHash < Hash
def initialize
raise "Constructor called"
end
end
class NewHash < Hash
def initialize(*args)
args.each_with_index do |val, index|
self[index] = val
end
end
end
class SubHashSettingInInitialize < Hash
def initialize(*args, &block)
self[:foo] = :bar
super(*args, &block)
end
end
class DefaultHash < Hash
def default(key)
100
end
end
class ToHashHash < Hash
def to_hash
{ "to_hash" => "was", "called!" => "duh." }
end
end
class KeyWithPrivateHash
private :hash
end
class ByIdentityKey
def hash
fail("#hash should not be called on compare_by_identity Hash")
end
end
class ByValueKey
attr_reader :n
def initialize(n)
@n = n
end
def hash
n
end
def eql? other
ByValueKey === other and @n == other.n
end
end
def self.empty_frozen_hash
@empty ||= {}
@empty.freeze
@empty
end
def self.frozen_hash
@hash ||= { 1 => 2, 3 => 4 }
@hash.freeze
@hash
end
end