Println?

I’m wondering if someone could point out to me an equivalent of the java
System.out.println method in the ruby standard lib.

I.e.
println 1,2,3 # concatenates, adds “\n”

Thanks much.
=r

It is puts

regards,
Vikas Sarin

Vikas Sarin wrote:

It is puts

puts would work, except I’m looking for one that concatenates, not adds
a new line per param.

puts 1,2,3
1
2
3

Thanks!
=r

print 1,2,3; puts

puts [1,2,3].to_s # ruby 1.8 only

puts [1,2,3].join

It is easy to make your own method which does any of these. The splat
operator is particularly helpful. e.g.

def println(*args)
print *args
puts
end

Vikas Sarin wrote:

It is puts

except that puts doesn’t add ‘\n’ if there is already one. I can’t
remember if println works the same way?

Cheers,
Mohit.
7/13/2009 | 7:54 PM.

print 1,2,3,"\n" would work!

regards,
Vikas Sarin

def println(*args)
print *args
puts
end

Nice. This is something I think should be in core, and might well
suggest it. Thoughts?
=r

2009/7/15 Roger P. [email protected]:

def println(*args)
 print *args
 puts
end

Nice. Â This is something I think should be in core, and might well
suggest it. Thoughts?

Name it: “sprint”

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs