mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user