From 16e0b5f0f4b8c89a97df2d4bd8cadd6b297c45cb Mon Sep 17 00:00:00 2001 From: Mik Date: Thu, 29 Apr 2021 19:16:53 +0200 Subject: [PATCH] Hash#keys_to_i! method --- lib/std++/main.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/std++/main.rb b/lib/std++/main.rb index d124ce96..7ac2a4e6 100644 --- a/lib/std++/main.rb +++ b/lib/std++/main.rb @@ -37,6 +37,15 @@ def to_s! self end + # Converts all keys to Integer + # @return [Hash] + def keys_to_i! + self.keys.each do |key| + self[key.to_i] = self.delete key if key.class != Integer + end + self + end + # Returns array of values with given keys # @param [Array] keys - Array of values # @return [Array]