The other day I came across another great use-case for Rubinius that might be useful for a lot of developers.
I use pry as my ruby REPL regularly. Often I feel the need to dig deeper into some part of the ruby stdlib. For example, just this week I wanted to find out what String.replace()
does. Reading the documentation I still felt the need to dig deeper and see what’s going on.
Using CRuby (the ruby version you’re probably using) one can see the source code in pry by installing the proper gem (gem install pry-doc
). Here’s the source code we got:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
As you can see there isn’t a lot we can understand about the internal behavior of this function without digging deeper into str_replace
, which isn’t really possible from pry.
Enter Rubinius
After you install rubinius (rvm install rbx --1.9
) and switch to it (rvm use rbx
) you can get a more interesting result (you might have to gem install pry
after switching to rubinius for the first time):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
Now, not only can we see that String#replace
replaces the contents of the String object we have with the contents of the other one (basically, treating String as a pointer and changing what it points to), we are free to dig deeper with the joys of ruby. For example, if we want to understand what StringValue
does we’re just a short show-source StringValue
away from it!
This simple ability is a valuable resource in getting intimate with ruby as a primary language. If you find more cool uses of this, please let me know.