Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created September 20, 2011 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/1229526 to your computer and use it in GitHub Desktop.
Save havenwood/1229526 to your computer and use it in GitHub Desktop.
Puts versus print in rbx
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