If you run my Ruby code

Yes, if you want. That way you can see the hash after you update it.

This is because when you run code, the memory is temporary, and is only held for the duration of the code. When the code finishes, any updates to variables/hash, etc gets ‘wiped’, and you go back to only having the source code. (A way around this would be to write to a file, but I’m not sure if that’s in the Ruby lessons, and I couldn’t tell you how to do it Ruby, although a quick ‘writing to file’ Google search should suffice if you’re interested).
I hope this helps!

My guess is that we need a real database ?

Yes, so to get around the issue of writing to a file, you can put the whole code (hash adding, updating, etc) inside a while loop (or until) which loops through the code until the user wants to exit.

All the ‘looping’ does is just extend the session beyond just 1 operation. when the program is closed the changes will be lost just the same ?

Yes they will, but at least you will be able to get multiple operations out of it, and see the additions you have made. If you were keen, you could learn how to read/write to a file, and just have it locally stored in the same folder as the code, using something like https://repl.it/.

Think for now just printing the hash after 1 operation is good to make sure the code actually works. maybe look into storing changes later. thanks

1 Like

Use repl to store the changes ?

Oh. I meant repl is a site which allows you to use many different languages and have multiple files with in the same repository. It just makes it easy to use reading/writing to files if you don’t have a Ruby compiler on your computer.

I have Ruby on my Linux, isn’t that an interpreter ?

Oh ok, then you can write Ruby on that and store files in the same place (i.e. on your desktop), in which case you wouldn’t need repl. I also suggested it because its environment is similar to that of CC.

Just to be clear: Ruby is interpreted not compiled ?

Ruby is compiled into bytecode instructions, which are then interpreted into machine code. You can read more about it here: https://buildingvts.com/the-structure-and-interpretation-of-ruby-programs-362db0412f29.

So, Ruby on my Linux is a compiler ? I don’t see where it makes an executable in my project folder.

I am not too familiar with the structure of Ruby compiling and Linux. If you are talking about something similar to Python’s IDLE, then you should be able to write code on that, and it automatically turns it into an executable file. You can then have text files that it reads/writes to. Alternatively, if you wanted to do it on your computer, but not on repl, you could use a text editor (like TextEdit or Notepad; I;m not sure what Linux uses), to write you code, then save it with a .rb (if I remember the Ruby extension), and run it like that.
Sorry I couldn’t be more help!

So. to be clear. I need to look up docs which say how to store the date locally, and if I want to share the program it has to store it in the cloud ?

If you want permanent storage, yes, you need to look up how to store things locally, on separate files. As for the cloud, that is the only way I know, but I could be wrong there, as I haven’t looked into that side of things very much.

If I share the program, do they need local or cloud storage ?

You should share all of the files, and therefore they would need to either download the files and store them locally, or use the cloud.

Ok thanks. catch you later

1 Like

One last question. is it a “just in time compiler” jit ?