0

Probably a really basic question, but I'll ask anyways. I tried googling my question but am having trouble getting results because I do not know the keywords to search. Any links for more info would be appreciated.

So, what happens to the value of a statement after execution? Maybe it's just because I'm in IRB that I am confusing myself. Example, if I am in IRB (Interactive Ruby) and execute the following: "Hello World"

Does the value disappear, forever lost? Or is it stored temporarily somewhere where it could be accessed? Thanks in advance!

Daiwik Daarun
  • 3,804
  • 7
  • 33
  • 60

1 Answers1

5

The value is stored to a temporary variable _ which always stores the last command run in IRB.

In actual script execution, the value would float away into the netherlands. If you wanted to save it, you should assign it to a variable.

hello_world = "Hello World!"
Dan Grahn
  • 9,044
  • 4
  • 37
  • 74
  • Exactly what I was looking for! Which leads me to a sub-question. If I am in one Ruby script (a), and (a) loads another Ruby Script(b) that only contains one statement, how do you get the value of the statement executed by (b) without being able to use the `_` variable? I know I could simply store the value in a variable but is there a way to do this without doing that? I am trying to use the `load` command on script (b) but when I store the value of load I only get a boolean indicating the script's load success. – Daiwik Daarun Dec 10 '13 at 21:11
  • @Mr_Skid_Marks StackOverflow doesn't support sub-questions. You should ask that as a new question (Ideally with a code sample that helps describe the problem) – Mark Thomas Dec 10 '13 at 21:53
  • Skid, there is a discussion of that [here](http://stackoverflow.com/questions/2635108/running-another-ruby-script-from-a-ruby-script). Also, [this article](http://blog.bigbinary.com/2012/10/18/backtick-system-exec-in-ruby.html) explains how you can run bash commands from within Ruby, should that be of interest. – Cary Swoveland Dec 10 '13 at 21:53
  • 1
    So every time we get a nil value error, the Dutch end up with an extra value? – Mark Thomas Dec 10 '13 at 21:57
  • 1
    That's true, @Mark. They Dutch love them, so much so that they name many of their children "Nils". They do have a surplus, however, so they now transship quite a few to Australia, which has a deficit. I am reminded of this [news item](http://www.ling.upenn.edu/~beatrice/humor/clinton-deploys-vowels.html), that appeared nearly 20 years ago. – Cary Swoveland Dec 11 '13 at 03:25