# All the core function are buit-in?

**URL:** <https://www.ruby-forum.com/t/all-the-core-function-are-buit-in/175414>\
**Category:** Ruby\
**Created:** [September 13, 2009, 9:10am UTC](https://www.ruby-forum.com/t/all-the-core-function-are-buit-in/175414 "2009-09-13T09:10:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![freekickr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/bc79bd/32.png) [@freekickr](https://www.ruby-forum.com/u/freekickr)\
**Post date:** [September 13, 2009, 9:10am UTC](https://www.ruby-forum.com/t/all-the-core-function-are-buit-in/175414/1 "2009-09-13T09:10:11Z")

</div>

Before posting, I went thru the offical doc and some searching forum,  
still hvn’t found how to view the ruby core component source code.

For example, I’d like to know how the Enumerable implemented the  
iterator, from the [RDoc Documentation](http://www.ruby-doc.org/core/), I can see following  
files are involved:

enum.c  
lib/set.rb  
lib/soap/property.rb  
ext/enumerator/enumerator.c

But how to check out the code above?

More things confusing me: For improving the performance, ruby builtin  
all the core component in parser?

Thanks.

---

<div class="post-metadata">

**Author:** ![freekickr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/bc79bd/32.png) [@freekickr](https://www.ruby-forum.com/u/freekickr)\
**Post date:** [September 13, 2009, 10:22am UTC](https://www.ruby-forum.com/t/all-the-core-function-are-buit-in/175414/2 "2009-09-13T10:22:20Z")

</div>

On Sep 13, 2009, at 00:10 , Free Kickr wrote:

> ext/enumerator/enumerator.c
> 
> But how to check out the code above?

- How to get Ruby

The Ruby distribution files can be found in the following FTP site:

ftp://ftp.ruby-lang.org/pub/ruby/

The trunk of the Ruby source tree can be checked out with the  
following command:

$ svn co [http://svn.ruby-lang.org/repos/ruby/trunk/](http://svn.ruby-lang.org/repos/ruby/trunk/) ruby

There are some other branches under development. Try the following  
command and see the list of branches:

$ svn ls [http://svn.ruby-lang.org/repos/ruby/branches/](http://svn.ruby-lang.org/repos/ruby/branches/)

> More things confusing me: For improving the performance, ruby builtin  
> all the core component in parser?

It should be (a bit) more clear once you have the code and can poke  
around.

---

<div class="post-metadata">

**Author:** ![freekickr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/bc79bd/32.png) [@freekickr](https://www.ruby-forum.com/u/freekickr)\
**Post date:** [September 13, 2009, 12:04pm UTC](https://www.ruby-forum.com/t/all-the-core-function-are-buit-in/175414/3 "2009-09-13T12:04:04Z")

</div>

Thanks, I download the files and have a brief read of the 4 files:

enum.c  
lib/set.rb  
lib/soap/property.rb  
ext/enumerator/enumerator.c

Which was told related to Enumerable module, but from those, I still did  
not understand the how the iterator implementation such as “collect,  
select, inject…etc”.

In my imagination, I thought, there’s Enumerable.rb which include the  
method  
def select…  
def collect…  
…

But it seems I was wrong, Could you pls give a little bit explaination?

Appreicated!

---

<div class="post-metadata">

**Author:** ![freekickr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/bc79bd/32.png) [@freekickr](https://www.ruby-forum.com/u/freekickr)\
**Post date:** [September 13, 2009, 2:55pm UTC](https://www.ruby-forum.com/t/all-the-core-function-are-buit-in/175414/4 "2009-09-13T14:55:38Z")

</div>

Hi –

On Sun, 13 Sep 2009, Free Kickr wrote:

> In my imagination, I thought, there’s Enumerable.rb which include the  
> method  
> def select…  
> def collect…  
> …
> 
> But it seems I was wrong, Could you pls give a little bit explaination?

Usually toward the end of the C files there’s a section where the C  
functions are bound to Ruby methods, like this:

```
 rb_define_method(rb_mEnumerable,"sort", enum_sort, 0);
 rb_define_method(rb_mEnumerable,"sort_by", enum_sort_by, 0);
 rb_define_method(rb_mEnumerable,"grep", enum_grep, 1);
 rb_define_method(rb_mEnumerable,"find", enum_find, -1);

```

etc. That’s your mapping from C to Ruby.

David

---

<div class="post-metadata">

**Author:** ![freekickr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/bc79bd/32.png) [@freekickr](https://www.ruby-forum.com/u/freekickr)\
**Post date:** [September 13, 2009, 3:55pm UTC](https://www.ruby-forum.com/t/all-the-core-function-are-buit-in/175414/5 "2009-09-13T15:55:58Z")

</div>

Yeh, I do have noticed that mapping, but I searched all the source code  
directory, did not find the ruby method definition …

eg. for the  
rb\_define\_method(rb\_mEnumerable, “collect”, enum\_collect, 0);  
but no source code file included string “enum\_collect”, only the static  
lib included …

I am not sure I have the source code tree, but I really downloaded all  
the ruby src tree by: $ svn co  
[http://svn.ruby-lang.org/repos/ruby/trunk/](http://svn.ruby-lang.org/repos/ruby/trunk/) ruby

Any help?

* * *

> Usually toward the end of the C files there’s a section where the C  
> functions are bound to Ruby methods, like this:
> 
> ```
> rb_define_method(rb_mEnumerable,"sort", enum_sort, 0);
> rb_define_method(rb_mEnumerable,"sort_by", enum_sort_by, 0);
> rb_define_method(rb_mEnumerable,"grep", enum_grep, 1);
> rb_define_method(rb_mEnumerable,"find", enum_find, -1);
> 
> ```
> 
> etc. That’s your mapping from C to Ruby.
> 
> David

* * *

---

<div class="post-metadata">

**Author:** ![freekickr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/bc79bd/32.png) [@freekickr](https://www.ruby-forum.com/u/freekickr)\
**Post date:** [September 13, 2009, 5:03pm UTC](https://www.ruby-forum.com/t/all-the-core-function-are-buit-in/175414/6 "2009-09-13T17:03:16Z")

</div>

## Begin to understand … Many Thanks …

> $ grep -B1 enum\_collect \*.c  
> enum.c-static VALUE  
> enum.c:enum\_collect(obj)
> 
> It should be there somewhere.
> 
> David

---

<div class="post-metadata">

**Author:** ![freekickr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/bc79bd/32.png) [@freekickr](https://www.ruby-forum.com/u/freekickr)\
**Post date:** [September 13, 2009, 4:37pm UTC](https://www.ruby-forum.com/t/all-the-core-function-are-buit-in/175414/7 "2009-09-13T16:37:28Z")

</div>

Hi –

On Sun, 13 Sep 2009, Through Pass wrote:

> [http://svn.ruby-lang.org/repos/ruby/trunk/](http://svn.ruby-lang.org/repos/ruby/trunk/) ruby
> 
> Any help?

$ grep -B1 enum\_collect \*.c  
enum.c-static VALUE  
enum.c:enum\_collect(obj)

It should be there somewhere.

David
