- Short Ruby Newsletter
- Posts
- How constant lookup works in Ruby
How constant lookup works in Ruby
#code #summary #ruby #how #constant #works #class #modules
This is a code summary for https://cirw.in/blog/constant-lookup
Code samples run on Ruby 3.1.2
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/9dac585d-b4d2-4159-b5f6-25aae6cbca59/76f3b6dd-c7be-4b3b-bd89-66110feaf0bf_1490x1212.png?t=1726892721)
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/9b35d02f-6e9c-4d06-8607-0c7a27691901/77348909-0401-4a76-8da7-4fde6b0b9561_1458x1366.png?t=1726892722)
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/fe44d241-3080-4356-8e7a-24995f240ca5/b5bb7c57-c2b6-43d6-8dc7-fc7de305a202_1442x1484.png?t=1726892723)
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/11818a35-0cc0-49f1-a843-2ae5bd5f1816/0dce9436-2c9c-4654-9871-3a1bb3a52c5e_1472x1502.png?t=1726892724)
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/50edada8-c55d-41ac-b3c5-d45029600dcd/13011dcf-4ce1-4493-ac1a-582b71468298_1458x1082.png?t=1726892724)
Find all the code I used to generate images here.
You should also read the full article I summarised here as I did not include all examples from the article, but only the most important ones.
Further reading:
I also found a gist that explains some of how constant lookup works in Ruby with code: Constant Lookup in Ruby
And also, this discussion in the Ruby lang issue tracker is important if you want to understand how all works deep down: https://bugs.ruby-lang.org/issues/18622
Reply