SlideShare uma empresa Scribd logo
1 de 68
Baixar para ler offline
May the Source Be with You
              Learning Ruby by Reading Ruby Source Code
Chimpr

12年12月8日星期六
12年12月8日星期六
I’m a Flash guy




                  ≈ 8 years
12年12月8日星期六
also a Ruby guy




                  ≈ 4 years
12年12月8日星期六
but not a C guy, yet!



12年12月8日星期六
Ruby   > Rails




12年12月8日星期六
share Ruby learning experiences in
              OpenFoundry and some developer party.




12年12月8日星期六
a SHOW-OFF person!




12年12月8日星期六
Learning Ruby
       by Reading Ruby Source Code




12年12月8日星期六
-   why read source code?
      -   how o sart?
      -   anything ineresting?
      -   wrie a simple Ruby Exension with C.




12年12月8日星期六
Why read source code?




12年12月8日星期六
see how the Ruby Core Team wrie Ruby




12年12月8日星期六
fun :)




12年12月8日星期六
"once you sart digging around in someone else’s
   code base, you’ll learn a lot about your own
   strengths and weaknesses" - Ruby Best Practice




              http://blog.rubybestpractices.com/posts/gregory/005-code-reading-stdlib.html
12年12月8日星期六
pre-requirement?




12年12月8日星期六
C language




12年12月8日星期六
curiosity and enthusiasm




12年12月8日星期六
What if I don’t have any skill of C?




12年12月8日星期六
Just learn it :)




12年12月8日星期六
How o Sart?




12年12月8日星期六
get Ruby source code

              download from Ruby websie:
              http://www.ruby-lang.org/en/

              or from github:
              https://github.com/ruby/ruby




12年12月8日星期六
Ruby Source Code:
              - *.c + *.h
              - *.rb (Sdlib)




12年12月8日星期六
Tools
              - Vim




12年12月8日星期六
Ruby 1.9.2 p290




12年12月8日星期六
Quick Browsing.. :)




12年12月8日星期六
what's a Ruby object?




12年12月8日星期六
sart from basic structure, like Object,
              Class, String, Array, Hash, Basic...




12年12月8日星期六
Object = RObject,
              Class = RClass,
              String = RString,
              Array = RArray,
              Hash = RHash,
              Basic = RBasic




12年12月8日星期六
“ruby.h”




12年12月8日星期六
“object.c”




12年12月8日星期六
Init_XXXX




12年12月8日星期六
class.c#350-354
              all Class’s class is Class!




12年12月8日星期六
class.c#556
              rb_define_module()




12年12月8日星期六
class.c#1170
              rb_define_method()




12年12月8日星期六
Object.c#2556~2560
 Integer(), Float(), String(), Array() are all
 global methods




12年12月8日星期六
class.c#1332
                 rb_define_global_function()

              = rb_define_module_method on kernel

              = rb_define_private_method on kernel +
                rb_define_singleton_method on kernel




12年12月8日星期六
“new”




12年12月8日星期六
class A
                def initialize
                  puts "hello"
                end
              end

              a = A.new



12年12月8日星期六
object.c#2624
              new ->
                rb_class_new_instance ->
                  rb_obj_alloc ->
                     rb_obj_call_init




12年12月8日星期六
o_s v.s o_str




12年12月8日星期六
String.c#7488
rb_define_method(rb_cString, "to_s", rb_str_to_s, 0);
rb_define_method(rb_cString, "to_str", rb_str_to_s, 0);




12年12月8日星期六
Array.c#4504
      rb_define_alias(rb_cArray, "to_s", "inspect");
      but no `to_str`




12年12月8日星期六
proc.c#2105
              how to execute a Proc?
              - proc.call
              - proc[]
              - proc === 123
              - proc.yield




12年12月8日星期六
object.c#2592
              -   attr
              -   attr_reader
              -   attr_writer
              -   attr_accessor




12年12月8日星期六
push v.s <<




12年12月8日星期六
array.c#709 (<<)
              VALUE
              rb_ary_push(VALUE ary, VALUE item){
                rb_ary_modify(ary);
                return rb_ary_push_1(ary, item);
              }




12年12月8日星期六
array.c#742 (push)
    static VALUE
    rb_ary_push_m(int argc, VALUE *argv, VALUE
    ary) {
      rb_ary_modify(ary);
      while (argc--) {
        rb_ary_push_1(ary, *argv++);
      }
      return ary;
    }



12年12月8日星期六
gc.c#3214-3215
              Object’s ID




12年12月8日星期六
gc.c#2865-2867
              How Symbol works?




12年12月8日星期六
people = {
          "Eddie" => ["green", "eddie@digik.com.tw"],
          "Joanne" => ["yellow", "hello@yahoo.com"]
        }

        people.map { |name, (color, email)|
          puts [name, email]
        }




12年12月8日星期六
people = {
          "Eddie" => ["green", "eddie@digik.com.tw"],
          "Joanne" => ["yellow", "hello@yahoo.com"]
        }

        people.map { |name, (_, email)|
          puts [name, email]
        }
        parse.y#8277-8299 shadowing_lvar_gen()



12年12月8日星期六
vm_eval.c#224
              method_missing




12年12月8日星期六
ineresting naming :)




12年12月8日星期六
ext/ripper/ripper.c#15890
          rb_intern, rb_intern2, rb_intern3




12年12月8日星期六
array.c#325
              rb_ary_new, rb_ary_new2, ary_new,
              rb_ary_new3, rb_ary_new4




12年12月8日星期六
Simple Ruby Exension from
                   Scrach




12年12月8日星期六
Conclusion




12年12月8日星期六
from basic structure




12年12月8日星期六
and don’t be afraid




12年12月8日星期六
References




12年12月8日星期六
Rubyソースコード完全解説
                   by 青木峰郎
               http://i.loveruby.net/ja/rhg/book/




12年12月8日星期六
Ruby Under a Microscope
                   by Pat Shaughnessy
              http://patshaughnessy.net/ruby-under-a-microscope




12年12月8日星期六
still not finish..




12年12月8日星期六
Ian Ruotsala

12年12月8日星期六
Hope can become a
Chimpr
              Jedi Master someday :)
12年12月8日星期六
おわり
              thank you all :)

12年12月8日星期六
any question?


12年12月8日星期六
Conacts
    高見見龍龍     Websie
              Blog
                         http://www.eddie.com.tw
                         http://blog.eddie.com.tw
              Plurk      http://www.plurk.com/aquarianboy
              Facebook   http://www.facebook.com/eddiekao
              Google Plus http://www.eddie.com.tw/+
              Twiter    https://twiter.com/#!/eddiekao
              Email      eddie@digik.com.tw
              Mobile     +886-928-617-687




                                                            photo by Eddie
12年12月8日星期六

Mais conteúdo relacionado

Semelhante a May the source_be_with_you

Concurrency model for mysql data processing@rubyconf.tw 2012
Concurrency model for mysql data processing@rubyconf.tw 2012Concurrency model for mysql data processing@rubyconf.tw 2012
Concurrency model for mysql data processing@rubyconf.tw 2012Mu-Fan Teng
 
Couch db@nosql+taiwan
Couch db@nosql+taiwanCouch db@nosql+taiwan
Couch db@nosql+taiwanKenzou Yeh
 
D2分享:让前端开发更高效
D2分享:让前端开发更高效D2分享:让前端开发更高效
D2分享:让前端开发更高效Berg Ray
 
Rails hello
Rails helloRails hello
Rails helloGump Law
 
Tqc+ 物件導向程式語言(java)認證研習會
Tqc+ 物件導向程式語言(java)認證研習會Tqc+ 物件導向程式語言(java)認證研習會
Tqc+ 物件導向程式語言(java)認證研習會Kyle Lin
 
Less
LessLess
Lesspswho
 
KISSY 1.3-released
KISSY 1.3-releasedKISSY 1.3-released
KISSY 1.3-releasedyiming he
 
一个前端Js模板引擎的实现和优化
一个前端Js模板引擎的实现和优化一个前端Js模板引擎的实现和优化
一个前端Js模板引擎的实现和优化tblanlan
 
Understanding Mobile Web Browser Performance
Understanding Mobile Web Browser PerformanceUnderstanding Mobile Web Browser Performance
Understanding Mobile Web Browser PerformanceBaidu, Inc.
 
Objc under the_hood_2013
Objc under the_hood_2013Objc under the_hood_2013
Objc under the_hood_2013Michael Pan
 
Node.js Quick Tour
Node.js Quick TourNode.js Quick Tour
Node.js Quick Tourmyzykj
 
Android vs e pub
Android vs e pubAndroid vs e pub
Android vs e pub永昇 陳
 

Semelhante a May the source_be_with_you (13)

Concurrency model for mysql data processing@rubyconf.tw 2012
Concurrency model for mysql data processing@rubyconf.tw 2012Concurrency model for mysql data processing@rubyconf.tw 2012
Concurrency model for mysql data processing@rubyconf.tw 2012
 
Couch db@nosql+taiwan
Couch db@nosql+taiwanCouch db@nosql+taiwan
Couch db@nosql+taiwan
 
Sourcemap
SourcemapSourcemap
Sourcemap
 
D2分享:让前端开发更高效
D2分享:让前端开发更高效D2分享:让前端开发更高效
D2分享:让前端开发更高效
 
Rails hello
Rails helloRails hello
Rails hello
 
Tqc+ 物件導向程式語言(java)認證研習會
Tqc+ 物件導向程式語言(java)認證研習會Tqc+ 物件導向程式語言(java)認證研習會
Tqc+ 物件導向程式語言(java)認證研習會
 
Less
LessLess
Less
 
KISSY 1.3-released
KISSY 1.3-releasedKISSY 1.3-released
KISSY 1.3-released
 
一个前端Js模板引擎的实现和优化
一个前端Js模板引擎的实现和优化一个前端Js模板引擎的实现和优化
一个前端Js模板引擎的实现和优化
 
Understanding Mobile Web Browser Performance
Understanding Mobile Web Browser PerformanceUnderstanding Mobile Web Browser Performance
Understanding Mobile Web Browser Performance
 
Objc under the_hood_2013
Objc under the_hood_2013Objc under the_hood_2013
Objc under the_hood_2013
 
Node.js Quick Tour
Node.js Quick TourNode.js Quick Tour
Node.js Quick Tour
 
Android vs e pub
Android vs e pubAndroid vs e pub
Android vs e pub
 

Mais de Eddie Kao

Rails girls in Taipei
Rails girls in TaipeiRails girls in Taipei
Rails girls in TaipeiEddie Kao
 
Rails Girls in Taipei
Rails Girls in TaipeiRails Girls in Taipei
Rails Girls in TaipeiEddie Kao
 
Let's Learn Ruby - Basic
Let's Learn Ruby - BasicLet's Learn Ruby - Basic
Let's Learn Ruby - BasicEddie Kao
 
from Ruby to Objective-C
from Ruby to Objective-Cfrom Ruby to Objective-C
from Ruby to Objective-CEddie Kao
 
Code Reading
Code ReadingCode Reading
Code ReadingEddie Kao
 
There is something about Event
There is something about EventThere is something about Event
There is something about EventEddie Kao
 
Flash Ecosystem and Open Source
Flash Ecosystem and Open SourceFlash Ecosystem and Open Source
Flash Ecosystem and Open SourceEddie Kao
 
Happy Programming with CoffeeScript
Happy Programming with CoffeeScriptHappy Programming with CoffeeScript
Happy Programming with CoffeeScriptEddie Kao
 
Ruby without rails
Ruby without railsRuby without rails
Ruby without railsEddie Kao
 
CoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-TuesdayCoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-TuesdayEddie Kao
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScriptEddie Kao
 
3rd AS Study Group
3rd AS Study Group3rd AS Study Group
3rd AS Study GroupEddie Kao
 
iOS Game Development with Cocos2d
iOS Game Development with Cocos2diOS Game Development with Cocos2d
iOS Game Development with Cocos2dEddie Kao
 
AS3讀書會(行前準備)
AS3讀書會(行前準備)AS3讀書會(行前準備)
AS3讀書會(行前準備)Eddie Kao
 
Misunderstanding about flash
Misunderstanding about flashMisunderstanding about flash
Misunderstanding about flashEddie Kao
 
Refactoring in AS3
Refactoring in AS3Refactoring in AS3
Refactoring in AS3Eddie Kao
 
AS3 Better Practices
AS3 Better PracticesAS3 Better Practices
AS3 Better PracticesEddie Kao
 

Mais de Eddie Kao (20)

Rails girls in Taipei
Rails girls in TaipeiRails girls in Taipei
Rails girls in Taipei
 
Rails Girls in Taipei
Rails Girls in TaipeiRails Girls in Taipei
Rails Girls in Taipei
 
Let's Learn Ruby - Basic
Let's Learn Ruby - BasicLet's Learn Ruby - Basic
Let's Learn Ruby - Basic
 
Vim
VimVim
Vim
 
from Ruby to Objective-C
from Ruby to Objective-Cfrom Ruby to Objective-C
from Ruby to Objective-C
 
Code Reading
Code ReadingCode Reading
Code Reading
 
There is something about Event
There is something about EventThere is something about Event
There is something about Event
 
Flash Ecosystem and Open Source
Flash Ecosystem and Open SourceFlash Ecosystem and Open Source
Flash Ecosystem and Open Source
 
Happy Programming with CoffeeScript
Happy Programming with CoffeeScriptHappy Programming with CoffeeScript
Happy Programming with CoffeeScript
 
Ruby without rails
Ruby without railsRuby without rails
Ruby without rails
 
CoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-TuesdayCoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-Tuesday
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
API Design
API DesignAPI Design
API Design
 
測試
測試測試
測試
 
3rd AS Study Group
3rd AS Study Group3rd AS Study Group
3rd AS Study Group
 
iOS Game Development with Cocos2d
iOS Game Development with Cocos2diOS Game Development with Cocos2d
iOS Game Development with Cocos2d
 
AS3讀書會(行前準備)
AS3讀書會(行前準備)AS3讀書會(行前準備)
AS3讀書會(行前準備)
 
Misunderstanding about flash
Misunderstanding about flashMisunderstanding about flash
Misunderstanding about flash
 
Refactoring in AS3
Refactoring in AS3Refactoring in AS3
Refactoring in AS3
 
AS3 Better Practices
AS3 Better PracticesAS3 Better Practices
AS3 Better Practices
 

May the source_be_with_you