diff options
| author | Tomoyuki Sahara <[email protected]> | 2014-06-19 09:57:08 +0900 |
|---|---|---|
| committer | Tomoyuki Sahara <[email protected]> | 2014-06-19 09:57:08 +0900 |
| commit | ddfc4eb5ef170e7eabc7b545366cac389139f044 (patch) | |
| tree | 6ea79d7afa09597181b062c8db53c3fb76ff4b82 /mrblib | |
| parent | d894de86f4429aba22055c8319fcf930ac39bdb4 (diff) | |
| download | mruby-ddfc4eb5ef170e7eabc7b545366cac389139f044.tar.gz mruby-ddfc4eb5ef170e7eabc7b545366cac389139f044.zip | |
IO#read(0) should return "" immediately. fixes iij/mruby-socket#13.
Diffstat (limited to 'mrblib')
| -rw-r--r-- | mrblib/io.rb | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/mrblib/io.rb b/mrblib/io.rb index 902d847d2..fceea1171 100644 --- a/mrblib/io.rb +++ b/mrblib/io.rb @@ -171,11 +171,16 @@ class IO end def read(length = nil) - unless length.nil? or length.class == Fixnum - raise TypeError.new "can't convert #{length.class} into Integer" - end - if length && length < 0 - raise ArgumentError.new "negative length: #{length} given" + unless length.nil? + unless length.is_a? Fixnum + raise TypeError.new "can't convert #{length.class} into Integer" + end + if length < 0 + raise ArgumentError.new "negative length: #{length} given" + end + if length == 0 + return "" # easy case + end end str = '' |
