From b026c4e912dec5a0d0ff78777cf77efcbe9be261 Mon Sep 17 00:00:00 2001 From: tufusa Date: Mon, 25 May 2026 21:27:09 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20`Hash`=20=E3=82=92=E5=AE=9A?= =?UTF-8?q?=E7=BE=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/hash.rbs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 core/hash.rbs diff --git a/core/hash.rbs b/core/hash.rbs new file mode 100644 index 0000000..bf25e91 --- /dev/null +++ b/core/hash.rbs @@ -0,0 +1,45 @@ +class Hash[unchecked out K, unchecked out V] < Object + include Enumerable[[K, V]] + + def initialize: () -> void + + def []: %a{implicitly-returns-nil} (K key) -> V + + def []=: (K key, V value) -> V + + def clear: () -> self + + def dup: () -> Hash[K, V] + + def delete: (K key) -> V? + + def empty?: () -> bool + + def has_key?: (K key) -> bool + + def has_value?: (V value) -> bool + + def key: (V value) -> K? + + def keys: () -> Array[K] + + def size: () -> Integer + + alias length size + + alias count size + + def merge: [U, W](Hash[U, W] other) -> Hash[K | U, V | W] + + def merge!: (Hash[K, V] other) -> self + + def values: () -> Array[V] + + def inspect: () -> String + def self.inspect: () -> String + + alias to_s inspect + alias self.to_s self.inspect + + def each: () { ([K, V]) -> void } -> self +end From 388ef28cbe90c96c066bd4633bb2a03ee7a9141c Mon Sep 17 00:00:00 2001 From: tufusa Date: Mon, 25 May 2026 21:27:22 +0900 Subject: [PATCH 2/3] =?UTF-8?q?chore:=20=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/hash.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test/hash.rb diff --git a/test/hash.rb b/test/hash.rb new file mode 100644 index 0000000..6bcfcee --- /dev/null +++ b/test/hash.rb @@ -0,0 +1,47 @@ +hash = { a: 1, b: 2, c: 3 } + +Hash.new + +hash[:a] + +hash[:a] = 2 + +hash.clear + +hash.dup + +hash.delete :a + +hash.empty? + +hash.has_key? :a + +hash.has_value? 0 + +hash.key 2 + +hash.keys + +hash.size + +hash.length + +hash.count + +hash.merge({}) +hash.merge({ 'a' => true, 5 => '' }) + +hash.merge!({ d: 4 }) + +hash.values + +hash.inspect +Hash.inspect + +hash.to_s +Hash.to_s + +hash.each do |key, value| + key + value +end From 8fd063fbfd8843e6b6fa316c8884c4c13c6839d8 Mon Sep 17 00:00:00 2001 From: tufusa Date: Mon, 25 May 2026 21:32:14 +0900 Subject: [PATCH 3/3] chore: rubocop --- test/hash.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/hash.rb b/test/hash.rb index 6bcfcee..67c2f6a 100644 --- a/test/hash.rb +++ b/test/hash.rb @@ -1,3 +1,9 @@ +# frozen_string_literal: true + +# rubocop:disable Lint/Void +# rubocop:disable Style/EmptyLiteral +# rubocop:disable Style/PreferredHashMethods + hash = { a: 1, b: 2, c: 3 } Hash.new @@ -45,3 +51,5 @@ key value end + +# rubocop:enable all