Double Gets as Heredoc #
From John Joyce in [ruby-talk:245343]:
I’m a little surprised at this. In irb, I tried
puts gets gets
. Why? I don’t know. But basically,gets gets
, seems to almost act like a heredoc!
Such a simple and unintended thing: the double-gets. Do you see how it works?
James H
Basically, the innermost gets takes a separator argument as the input from the outermost gets .
Proof:
chris2
The first gets gets the gets seperator while the second gets gets the text using the gets serperator.
Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo.
netghost
Now that is really neat!
Hank
I like
gets puts
too.But otherwise, thats pretty cool.
Jon Leighton
Hank: I don’t see what
gets puts
does?nertzy
gets puts
is the same asgets nil
sinceputs
without any parameters returnsnil
. Thus, there isn’t any separator.RSL
Hank: you didn’t warn me that you needed to CTRL +D get close the input there. You just ate my o`o!!! [I dunno what my o`o is though.]
rluv
RSL , that sounds like a personal problem.
leethal
puts gets ferrets that has hats with stats
murphy
wow :) heredocs, indeed.
robert
nothing to do with this problem: didn’t you have a webpage with programms that could execute the page, ähm the page was actually a programm. omy this lost link is like a hole in my head. or did i dream or something…
John Joyce
Thanks to James Edward Gray II ’s great explanation, it made perfect sense. I also tried subsequent oddities like gets puts and stuff. Ruby is fun to screw with even when you don’t fully know what you’re doing! Not many languages are as easy to screw around with. I just with unicode was native in Ruby so that characters beyond ascii would behave more predicably and less surprisingly…. Oh and _Why? You’re just very Austin/San Marcos, Texas. Those vibes are running strong in the Ruby community so that’s pretty freaky to some folks coming at it with hardened years of other stuff.
John Joyce
gets gets
isn’tgets gets
without puts.puts gets gets
Heck this could easily make a flexible little goofy tool with a prompt for interactivity or simply as a tool to request input. Only problem is it’s dangerous if exposed to the unknown/untrusted outside world. overflow city? Needs some checking for data size, and something to prevent any further injection of code, in case the text goes somewhere that it might matter! (I wish I knew as much about programming as ya’ll do, then I’d be able to use this stuff to do more stuff)