From ddfc4eb5ef170e7eabc7b545366cac389139f044 Mon Sep 17 00:00:00 2001 From: Tomoyuki Sahara Date: Thu, 19 Jun 2014 09:57:08 +0900 Subject: IO#read(0) should return "" immediately. fixes iij/mruby-socket#13. --- mrblib/io.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'mrblib') 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 = '' -- cgit v1.2.3