Return of gets gets
Not long ago I posted about
I said it acted a bit like a Heredoc.
I've since realized that it is actually more similar to
In fact, it behaves identically thus far.
irb(main):004:0> lines = readlines
=> ["ff\n", "fff\n", "akenll329\n", "\\n\n", "kls\n"]
irb(main):005:0> puts lines
irb(main):006:0> lines = gets gets
=> "ff\nahoy\n\\n\nlll ll\n"
irb(main):007:0> puts lines
Now if you create a file such as:
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:
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
readlines.length will return the number of lines.
gets gets.length will return the number of characters.
|All times are GMT. The time now is 06:35 AM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.