All the core function are buit-in?

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 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.

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/ 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/

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.

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!

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

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/ 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


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

Hi –

On Sun, 13 Sep 2009, Through Pass wrote:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs