Ruby/Language Basics/STDOUT
Материал из Wiki.crossplatform.ru
(Различия между версиями)
Версия 17:10, 26 мая 2010
Single-character output
o = STDOUT o.putc(65) # Write single byte 65 (capital A) o.putc("B") # Write single byte 66 (capital B) o.putc("CD") # Write just the first byte of the string
String output to STDOUT
o = STDOUT o << x # Output x.to_s o << x << y # May be chained: output x.to_s + y.to_s o.print # Output $_ + $\ o.print s # Output s.to_s + $\ o.print s,t # Output s.to_s + t.to_s + $\ o.printf fmt,*args # Outputs fmt%[args] o.puts # Output newline o.puts x # Output x.to_s.chomp plus newline o.puts x,y # Output x.to_s.chomp, newline, y.to_s.chomp, newline o.puts [x,y] # Same as above o.write s # Output s.to_s, returns s.to_s.length o.syswrite s # Low-level version of write