Best way to learn Ruby internals

Hi all,

While I love Ruby, I must admit, I only have a small amount of knowledge of
how Ruby "pickles my onion". Being someone who likes to know how things
work, I'd love to dive into Ruby's source code but before I blindly go
where many people have gone before, I was wondering what you lovely
Rubyists would recommend doing. Is Ruby similar to Python (excuse my
language) in the sense it is compiled to bytecode and an interpreter runs
it implicitly? Any videos/articles you have on Ruby's internals would be
appreciated. I have a feeling the main documentation might be the best
choice to start but videos would be preferable.

Robert

Why did you turn to Ruby, and not, say, C++?

(Asking because Ruby, just like Python or JavaScript, can easily be a wrong choice, and you didn't tell the purpose at all.)

Yuri

···

On 01/11/18 16:07, Robert O'Shea wrote:

While I love Ruby, I must admit, I only have a small amount of knowledge of how Ruby "pickles my onion".

Ah yes, I generally hack around with Ruby, simple scripts here and there to
automate things or simply to see if I can mimic simple cli commands, like
'ls', 'grep' (not as robust but semi functional) etc. I use it for quick
prototyping also, if I have an idea I'll break out Ruby and code it up
dynamically typed before I even think of doing it statically typed.

It's really just a topic of interest really, that I want to understand
Ruby's internals, give myself some inspiration, learn a thing or two in the
process. Although really I could shift my interest to something less robust
like Lua but I'm not a fan of that language. So really my answer is
curiosity, perhaps I could also end up contributing to a flavour of Ruby in
the future.

Also it increases my C knowledge, I need to work on my C++ but I seem to
prefer C.

···

On Fri 12 Jan 2018, 00:12 Yuri, <yuri@rawbw.com> wrote:

On 01/11/18 16:07, Robert O'Shea wrote:
> While I love Ruby, I must admit, I only have a small amount of
> knowledge of how Ruby "pickles my onion".

Why did you turn to Ruby, and not, say, C++?

(Asking because Ruby, just like Python or JavaScript, can easily be a
wrong choice, and you didn't tell the purpose at all.)

Yuri

I've done a little C, and given that the things I'm interested in (Ruby,
Python, MongoDB, Linux kernel) are written in it, I think it's more useful
than C++. I'd probably choose Go over C++.

Of course, I'm not a professional coder so there's that...

Leam

···

On Thu, Jan 11, 2018 at 7:27 PM, Robert O'Shea <robertoshea2k11@gmail.com> wrote

Also it increases my C knowledge, I need to work on my C++ but I seem to
prefer C

Hello,

Talking about Ruby internals, There is a great book called "Ruby Under a
Microscope". I recommend you read it.
Me too I am someone who likes to know how things work internally so I get
exactly what you're feeling :slight_smile:

···

2018-01-12 0:32 GMT+00:00 leam hall <leamhall@gmail.com>:

On Thu, Jan 11, 2018 at 7:27 PM, Robert O'Shea <robertoshea2k11@gmail.com> > wrote

Also it increases my C knowledge, I need to work on my C++ but I seem to
prefer C

I've done a little C, and given that the things I'm interested in (Ruby,
Python, MongoDB, Linux kernel) are written in it, I think it's more useful
than C++. I'd probably choose Go over C++.

Of course, I'm not a professional coder so there's that...

Leam

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

If you're diving under the hood, it's important to remember the
difference between "Ruby" (the language -- syntax, semantics, core,
standard libraries, etc.) and the various interpreters/compilers out
there. If you want to do some research, look up "YARV" (Yet Another
Ruby VM) and its predecessor "MRI" (Matz's Ruby Interpreter), and then
jump over and have a look at JRuby (which runs Ruby source on the JVM,
via Java bytecode).

I'd talk more, but I'm technically at work, technically not working on
Ruby stuff at the moment.

Cheers

···

On 12 January 2018 at 10:07, Robert O'Shea <robertoshea2k11@gmail.com> wrote:

Hi all,

While I love Ruby, I must admit, I only have a small amount of knowledge of
how Ruby "pickles my onion". Being someone who likes to know how things
work, I'd love to dive into Ruby's source code but before I blindly go where
many people have gone before, I was wondering what you lovely Rubyists would
recommend doing. Is Ruby similar to Python (excuse my language) in the sense
it is compiled to bytecode and an interpreter runs it implicitly? Any
videos/articles you have on Ruby's internals would be appreciated. I have a
feeling the main documentation might be the best choice to start but videos
would be preferable.

Robert

--
  Matthew Kerwin
  http://matthew.kerwin.net.au/

AFAIK The best way to start learning how Ruby works internally is
the book "Ruby Under a Microscope".
[ I agree with BAZZAOUI].

But, I reccomend you to try to undestand well the Ruby language
before reading that book. To that aim, I reccomend you the
book "The Ruby Programming Language".
It is dated but still a very usefull resource.

If you know already C, Java, Python, Perl ... etc be carefull with blocks and scope.
Also read well the stuff about Threads.

bye
Nicola

···

On 12/01/2018 01:07, Robert O'Shea wrote:

Hi all,

While I love Ruby, I must admit, I only have a small amount of knowledge of how Ruby "pickles my onion". Being someone who likes to know how things work, I'd love to dive into Ruby's source code but before I blindly go where many people have gone before, I was wondering what you lovely Rubyists would recommend doing. Is Ruby similar to Python (excuse my language) in the sense it is compiled to bytecode and an interpreter runs it implicitly? Any videos/articles you have on Ruby's internals would be appreciated. I have a feeling the main documentation might be the best choice to start but videos would be preferable.

Robert

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Is Ruby similar to Python (excuse my
language) in the sense it is compiled to bytecode and an interpreter runs
it implicitly?

I'm not familiar with how Python works, but what you describe is
similar for Ruby: parse.y -> compile.c.

insns.def defines the YARV instructions which get parsed and
made into the main VM loop. Learning the bytecode language is
a good step towards learning a real machine assembly language
(e.g. ARM), which will in turn reinforce your understanding of C.

Any videos/articles you have on Ruby's internals would be
appreciated. I have a feeling the main documentation might be the best
choice to start but videos would be preferable.

There is no "best" overall; just "best" for you. So I don't
know if what worked for me will work for you...

I have no recommendation on videos or books; but
doc/extension.rdoc in the source tree (formerly README.EXT) is
required reading and free.

For Learning any C project: ctags or similar is helpful to jump
around, as is cflow at times.

As for learning C itself: know and understand unions well,
I consider unions quintessential to understanding C.
And integer representations and bitwise operations (but those
are in other languages).

You should already understand pointers since it's how variables
work in Ruby.

If you've used Ruby a bunch, you should already understand how
classes, modules, methods, constants relate to each other.
Those all map to the underlying relationships implemented in C.

Learn C before C++; because one is mostly a subset of the other.
C is a small language; many projects use it the same ways Ruby
does, so you'll find it easy to jump to most other C projects.

···

Robert O'Shea <robertoshea2k11@gmail.com> wrote:

I have a good knowledge of C, my deficiency is the fact I have never read
or wrote large programs like Ruby. I plan on writing an interpreter in
C/C++ at some stage, in the style of Python or Ruby, I love both so I am
inspired by both. It'll be a difficult task and I plan to document it with
some blog posts, won't be a weekly thing though

···

On Fri 12 Jan 2018, 09:10 Eric Wong, <e@80x24.org> wrote:

Robert O'Shea <robertoshea2k11@gmail.com> wrote:
> Is Ruby similar to Python (excuse my
> language) in the sense it is compiled to bytecode and an interpreter runs
> it implicitly?

I'm not familiar with how Python works, but what you describe is
similar for Ruby: parse.y -> compile.c.

insns.def defines the YARV instructions which get parsed and
made into the main VM loop. Learning the bytecode language is
a good step towards learning a real machine assembly language
(e.g. ARM), which will in turn reinforce your understanding of C.

> Any videos/articles you have on Ruby's internals would be
> appreciated. I have a feeling the main documentation might be the best
> choice to start but videos would be preferable.

There is no "best" overall; just "best" for you. So I don't
know if what worked for me will work for you...

I have no recommendation on videos or books; but
doc/extension.rdoc in the source tree (formerly README.EXT) is
required reading and free.

For Learning any C project: ctags or similar is helpful to jump
around, as is cflow at times.

As for learning C itself: know and understand unions well,
I consider unions quintessential to understanding C.
And integer representations and bitwise operations (but those
are in other languages).

You should already understand pointers since it's how variables
work in Ruby.

If you've used Ruby a bunch, you should already understand how
classes, modules, methods, constants relate to each other.
Those all map to the underlying relationships implemented in C.

Learn C before C++; because one is mostly a subset of the other.
C is a small language; many projects use it the same ways Ruby
does, so you'll find it easy to jump to most other C projects.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;