0

I am very new to coding, just installed Visual Studio Code with WSL Ubuntu extension. I wanted to play around a little bit get a feel of how everything works so I started by running a very simple "hello world" code in Ruby.

editor with starting version

The output came out fine but then I changed the str1 to "Not hello" and then tried running the code again but the terminal is still outputting the old results. It still keeps saying "hello world" and not "Not hello world".

editor after changes

I tried this with many different types of simple codes and the terminal still runs the old code instead of the new one.

This might be a very simple fix and I am too new to understand. What do I do so the terminal runs the newest updated code?


pjs
  • 18,696
  • 4
  • 27
  • 56
  • Does this answer your question? [Why don't other programs see the changes I made to a file in VS Code until I save those changes?](https://stackoverflow.com/questions/76984829/why-dont-other-programs-see-the-changes-i-made-to-a-file-in-vs-code-until-i-sav) – starball Aug 27 '23 at 06:14

1 Answers1

0

If you create a new file edit session, the contents are stored in a buffer in memory within the editor until you issue a save command. Alternatively, if you load an existing file into your editor, you read the file's contents into an edit buffer. Either way, there are now two separate copies: the one in the buffer and the one stored in your file system. Revisions made to the editor's buffer are independent of the file system copy until you explicitly save the edit buffer. Editors such as VS Code give you a visual notification of this on the edit tab. There will be an "x" on the tab when the buffer and the file are synchronized, and a dot when the buffer has been altered but not yet saved.

When you run ruby from the command line, it applies the ruby interpreter to the file system copy of your program. Unsaved edits don't exist in that copy, so they're not reflected in the output. To fix this, save your editor before trying to run the program.

Even after 50 years of coding I still make this mistake occasionally. If you don't see results from an edit you just made, check the edit tab. If there's a dot rather than an "x", save and rerun.

pjs
  • 18,696
  • 4
  • 27
  • 56