]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
fix: write override behavior
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 2 Jun 2021 19:31:20 +0000 (21:31 +0200)
committerMatthias Hecker <36882671+mattzque@users.noreply.github.com>
Sat, 5 Jun 2021 16:06:45 +0000 (18:06 +0200)
IO.write() takes an arbitrary number of argumens, that are converted to string
and joined on write. We should behave the same way.

Moreover, the returned value is the number of bytes, and this is bytesize
in modern Ruby.

lib/rbot/ircbot.rb

index f9f1758ac87ddeb7e0efd6a3034db5b10297ddd1..564403f5d3bdfb7868708e6a874bc1cb0ae59b4e 100644 (file)
@@ -444,17 +444,19 @@ class Bot
         end
       end
 
-      def $stdout.write(str=nil)
+      def $stdout.write(*args)
+        str = args.map { |s| s.to_s }.join("")
         log str, 2
-        return str.to_s.size
+        return str.bytesize
       end
-      def $stderr.write(str=nil)
+      def $stderr.write(*args)
+        str = args.map { |s| s.to_s }.join("")
         if str.to_s.match(/:\d+: warning:/)
           warning str, 2
         else
           error str, 2
         end
-        return str.to_s.size
+        return str.bytesize
       end
 
       LoggerManager.instance.log_session_start