All the core function are buit-in?

F

Free Kickr

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

Ryan Davis

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?

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

Free Kickr

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!
 
D

David A. Black

Hi --

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?

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
 
T

Through Pass

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?

-----------------
 
D

David A. Black

Hi --

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?

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

It should be there somewhere.


David
 
T

Through Pass

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top