diff --git a/lib/sorted_containers/sorted_hash.rb b/lib/sorted_containers/sorted_hash.rb index 01b0f83..77f33a2 100644 --- a/lib/sorted_containers/sorted_hash.rb +++ b/lib/sorted_containers/sorted_hash.rb @@ -58,6 +58,7 @@ def delete(key) # # @return [Array] A two-element array containing the key and value of the first key-value pair. def first + return nil if @sorted_array.empty? key = @sorted_array.first [key, @hash[key]] end @@ -66,6 +67,7 @@ def first # # @return [Array] A two-element array containing the key and value of the first key-value pair. def last + return nil if @sorted_array.empty? key = @sorted_array.last [key, @hash[key]] end