define IO#hash to override Enumerable#hash. fixes #73.

Current implementation of Enumerable#hash calls #each to collect
hash values of enumerated objects (then calculates the hash value
of the Enumerable object).  But IO#each is a method to read lines.
It is not expected that IO#hash reads all lines from the IO object.
Or even worse, program waits for the IO object to be readable if
it is a socket or something cannot be read immediately.
This commit is contained in:
Tomoyuki Sahara
2017-02-08 18:31:50 +09:00
parent 69623078a8
commit caab1c203c
+6
View File
@@ -114,6 +114,12 @@ class IO
self
end
def hash
# We must define IO#hash here because IO includes Enumerable and
# Enumerable#hash will call IO#read...
self.__id__
end
def write(string)
str = string.is_a?(String) ? string : string.to_s
return str.size unless str.size > 0