Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Ruby puts function confusing me.

Name: nick 2013-07-10 18:32

Can someone help me with ruby?

I am following a guide to learn rails here, with no prior ruby knowledge. I am relatively knowledgeable in python, and I know django pretty well.

Something that is very confusing to me is if I type in the rails console this code snippit.

>3.times { puts "Betelgeuse!" }

the output is this.

"Betelgeuse!"
"Betelgeuse!"
"Betelgeuse!"
=> 3

In all other instances of using the puts function, that last line has been '=> nil'. Why is this now changing?

Thank you in advance.

Name: Anonymous 2013-07-10 18:48

>>3
That's Ruby's built-in memory analyzer.  When it returns a number, it is an approximation of the number of bytes of memory that have leaked during an operation.  Normal puts pretty much directly ties into the implementing runtime, so it's fine, but as the naive GC comment by >>2-san points out, mutable string allocation must be done repeatedly in loops, as opposed to the immutable constant declaration that can be assumed.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List