Ruby

8 Things I've Learned about Ruby Internals from 30 Minutes of Ruby Under the Microscope

Some small learnings about big Ruby thingies.
8 Things I've Learned about Ruby Internals from 30 Minutes of Ruby Under the Microscope
In: Ruby

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:

  1. 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)
  2. the process from your file.rb to execution is:
    a. Tokenization
    b. Parsing
    c. Compilation
  3. tokenization and parsing seem to happen kind of in parallel
  4. tokenization divides your code into tokens but is agnostic to syntax
  5. tokenization relies on a huge file called parse.y that has a huge switch statement that guides the tokenizer to get the tokens right
  6. 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 πŸ¦ΎπŸ€–
  7. parsing makes sure your syntax is correct
  8. 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.

Comments
More from RichStone Input Output
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to RichStone Input Output.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.