OK, this will be a short one because above all I've learned that it's fine to ditch, even a great book, after half an hour. Having stopped reading the book somewhere during the first chapter.
Still, there are some nice fun facts about ruby internals that I found in this truly awesome book:
- ruby reads your code 3(!) times before executing it (that's an amazing fun fact to start a chapter of a book about Ruby, just FYI)
- the process from your file.rb to execution is:
a. Tokenization
b. Parsing
c. Compilation - tokenization and parsing seem to happen kind of in parallel
- tokenization divides your code into tokens but is agnostic to syntax
- tokenization relies on a huge file called
parse.y
that has a huge switch statement that guides the tokenizer to get the tokens right - the tokenizer reads your
.rb
file character by character and checks if it finds a rule for this character in the parse.y file.
=> For example, if it encounters<
it's so smart that on the next char it decides whether it's a lesser_than operator or if it's a<<
method π¦Ύπ€ - parsing makes sure your syntax is correct
- then Ruby goes over to compilation, creating the actual instructions for a computer to execute
OK, writing all this down makes me wanna go back to the book. But I'll park it for now and let it breed until I decide to do some Ruby open-source coding on Ruby 4.x or something.