# Return of gets gets

**URL:** <https://www.ruby-forum.com/t/return-of-gets-gets/92729>\
**Category:** Ruby\
**Created:** [April 23, 2007, 3:39pm UTC](https://www.ruby-forum.com/t/return-of-gets-gets/92729 "2007-04-23T15:39:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [April 23, 2007, 3:39pm UTC](https://www.ruby-forum.com/t/return-of-gets-gets/92729/1 "2007-04-23T15:39:12Z")

</div>

Not long ago I posted about  
gets gets

I said it acted a bit like a Heredoc.  
I’ve since realized that it is actually more similar to  
readlines  
In fact, it behaves identically thus far.  
example:  
irb(main):004:0\> lines = readlines  
ff  
fff  
akenll329  
\n  
kls  
=\> [“ff\n”, “fff\n”, “akenll329\n”, “\n\n”, “kls\n”]  
irb(main):005:0\> puts lines  
ff  
fff  
akenll329  
\n  
kls  
=\> nil  
irb(main):006:0\> lines = gets gets  
fff  
ff  
ahoy  
\n  
lll ll  
=\> “ff\nahoy\n\n\nlll ll\n”  
irb(main):007:0\> puts lines  
ff  
ahoy  
\n  
lll ll  
=\> nil

Now if you create a file such as:  
putsgetsgets.rb

containing only:  
puts gets gets

Then run the file, passing it some other file’s text:  
ruby putsgetsgets.rb \< otherfile.whatever

It will output the same same as if you create a file:  
putsreadlines.rb

Containing:  
puts readlines

Then do the same:  
ruby putsreadlines.rb \< otherfile.whatever

The difference is of course it is not a developed method like  
readlines. Thus, it doesn’t respond quite the same to methods such as  
length.  
readlines.length will return the number of lines.  
gets gets.length will return the number of characters.
