Created
September 20, 2011 16:07
-
-
Save havenwood/1229526 to your computer and use it in GitHub Desktop.
Puts versus print in rbx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def puts(*a) | |
$stdout.puts(*a) | |
nil | |
end | |
def puts(*args) | |
if args.empty? | |
write DEFAULT_RECORD_SEPARATOR | |
else | |
args.each do |arg| | |
if arg.equal? nil | |
str = "nil" | |
elsif Thread.guarding? arg | |
str = "[...]" | |
elsif arg.kind_of?(Array) | |
Thread.recursion_guard arg do | |
arg.each do |a| | |
puts a | |
end | |
end | |
else | |
str = arg.to_s | |
end | |
if str | |
write str | |
write DEFAULT_RECORD_SEPARATOR unless str.suffix?(DEFAULT_RECORD_SEPARATOR) | |
end | |
end | |
end | |
nil | |
end | |
def print(*args) | |
args.each do |obj| | |
$stdout.write obj.to_s | |
end | |
nil | |
end | |
def print(*args) | |
if args.empty? | |
write $_.to_s | |
else | |
args.each { |o| write o.to_s } | |
end | |
write $\.to_s | |
nil | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment