diff options
| author | Tomoyuki Sahara <[email protected]> | 2017-02-08 18:31:50 +0900 |
|---|---|---|
| committer | Tomoyuki Sahara <[email protected]> | 2017-02-08 18:31:50 +0900 |
| commit | caab1c203cc996c521fc7115aab0991e1e53e05c (patch) | |
| tree | 34c175c609d8650650cfd2c290de6fbd3e042fc0 | |
| parent | 69623078a86b45617a6fdbe0238c147e280ad9db (diff) | |
| download | mruby-caab1c203cc996c521fc7115aab0991e1e53e05c.tar.gz mruby-caab1c203cc996c521fc7115aab0991e1e53e05c.zip | |
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.
| -rw-r--r-- | mrblib/io.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/mrblib/io.rb b/mrblib/io.rb index 0b10c82aa..08f9180dd 100644 --- a/mrblib/io.rb +++ b/mrblib/io.rb @@ -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 |
