Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > All the core function are buit-in?

Reply
Thread Tools

All the core function are buit-in?

 
 
Free Kickr
Guest
Posts: n/a
 
      09-13-2009
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.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Ryan Davis
Guest
Posts: n/a
 
      09-13-2009

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

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


 
Reply With Quote
 
 
 
 
Free Kickr
Guest
Posts: n/a
 
      09-13-2009
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!
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
David A. Black
Guest
Posts: n/a
 
      09-13-2009
Hi --

On Sun, 13 Sep 2009, Free Kickr wrote:

> 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

--
David A. Black, Director
Ruby Power and Light, LLC (http://www.rubypal.com)
Ruby/Rails training, consulting, mentoring, code review
Book: The Well-Grounded Rubyist (http://www.manning.com/black2)

 
Reply With Quote
 
Through Pass
Guest
Posts: n/a
 
      09-13-2009
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

----------------
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
David A. Black
Guest
Posts: n/a
 
      09-13-2009
Hi --

On Sun, 13 Sep 2009, Through Pass wrote:

> 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

--
David A. Black, Director
Ruby Power and Light, LLC (http://www.rubypal.com)
Ruby/Rails training, consulting, mentoring, code review
Book: The Well-Grounded Rubyist (http://www.manning.com/black2)

 
Reply With Quote
 
Through Pass
Guest
Posts: n/a
 
      09-13-2009
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


--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
From single core to dual core =?Utf-8?B?Q2FybG9z?= Windows 64bit 26 08-06-2006 09:08 PM
Core Solo & Core Duo are not Core microarchitecture; 65nm Pentium M chips bigal Hardware 0 03-22-2006 11:24 AM
Dual Core Vs Single Core Processor Real World Performance Difference Edge Computer Information 3 03-15-2006 01:30 AM
posible: dual core + single core =?Utf-8?B?TmllbHMgQ2hyLg==?= Windows 64bit 7 11-22-2005 06:11 PM
Fedora Core 3 & Core 4 Password questions Brandon Computer Security 4 08-15-2005 04:30 AM



Advertisments