Skip to content
This repository
Browse code

Init project

  • Loading branch information...
commit 8768db2fb1b707c779b825c22c3ae61d4e2fa37a 0 parents
Wen-Tien Chang ihower authored

Showing 28 changed files with 2,603 additions and 0 deletions. Show diff stats Hide diff stats

  1. +2 0  .gitignore
  2. +12 0 README.textile
  3. +133 0 about.textile
  4. +129 0 about.zh_TW.textile
  5. +31 0 community.conferences.textile
  6. +76 0 community.ruby-core.textile
  7. +36 0 community.textile
  8. +32 0 community.weblogs.textile
  9. +118 0 documentation.quickstart.textile
  10. +429 0 documentation.ruby-from-other-languages.textile
  11. +148 0 documentation.ruby-from-other-languages.to-ruby-from-c-and-c-.textile
  12. +42 0 documentation.ruby-from-other-languages.to-ruby-from-java.textile
  13. +50 0 documentation.ruby-from-other-languages.to-ruby-from-perl.textile
  14. +39 0 documentation.ruby-from-other-languages.to-ruby-from-php.textile
  15. +55 0 documentation.ruby-from-other-languages.to-ruby-from-python.textile
  16. +42 0 documentation.success-stories.textile
  17. +66 0 documentation.textile
  18. +86 0 download.textile
  19. +12 0 generate.rb
  20. +11 0 layout.html
  21. +77 0 libraries.textile
  22. +24 0 libraries.top-projects.textile
  23. +31 0 mailing-lists.manual-instructions.textile
  24. +42 0 mailing-lists.textile
  25. 0  output/.gitignore
  26. +843 0 output/oldstyle.css
  27. +21 0 security.textile
  28. +16 0 user-groups.textile
2  .gitignore
... ... @@ -0,0 +1,2 @@
  1 +output/*.html
  2 +.DS_Store
12 README.textile
Source Rendered
... ... @@ -0,0 +1,12 @@
  1 +h1. "ruby-lang.org/zh_TW":http://ruby-lang.org/zh_TW
  2 +
  3 +The original content is from "http://ruby-lang.org":http://ruby-lang.org (using "Rediant CMS":http://radiantcms.org/)
  4 +
  5 +h2. USAGE
  6 +
  7 +type "ruby generate.rb" will generate HTML to /output
  8 +
  9 +h2. zh-TW site maintainers
  10 +
  11 +* SJH
  12 +* ihower
133 about.textile
Source Rendered
... ... @@ -0,0 +1,133 @@
  1 +Wondering why Ruby is so popular? Its fans call it a beautiful, artful language. And yet, they say it's handy and practical. What gives?
  2 +
  3 +h3. The Ideals of Ruby's Creator
  4 +
  5 +!>{padding-left:8px}http://redhanded.hobix.com/images/ruby-lang-matz.png!
  6 +
  7 +Ruby is a language of careful balance. Its creator, <a href="http://www.rubyist.net/~matz/">Yukihiro "matz" Matsumoto</a>, blended parts of his favorite languages (Perl, Smalltalk, Eiffel, Ada, and Lisp) to form a new language that balanced functional programming with imperative programming.
  8 +
  9 +He has often said that he is "trying to make Ruby natural, not simple," in a way that mirrors life.
  10 +
  11 +Building on this, he adds:
  12 +
  13 +bq. Ruby is simple in appearance, but is very complex inside, just like our human body[1].
  14 +
  15 +h3. About Ruby's Growth
  16 +
  17 +Since its public release in 1995, Ruby has drawn devoted coders worldwide. In 2006, Ruby achieved mass acceptance. With active user groups formed in the world's major cities and Ruby-related conferences filled to capacity.
  18 +
  19 +!>{padding-left:8px}http://gmane.org/plot-rate.php?group=gmane.comp.lang.ruby.general&width=280&height=140&title=Ruby-Talk+Activity+over+4+Years(Graph courtesy of Gmane.)!
  20 +
  21 +Ruby-Talk, the primary "mailing list":/en/community/mailing-lists/ for discussion of the Ruby language has climbed to an average of 200 messages per day.
  22 +
  23 +The TIOBE index, which measures the growth of programming languages, ranks Ruby as #9 among programming languages worldwide. Much of the growth is attributed to the popularity of software written in Ruby, particularly the Ruby on Rails web framework[2].
  24 +
  25 +Ruby is also "totally free":./license.txt. Not only free of charge, but also free to use, copy, modify, and distribute.
  26 +
  27 +h3. Seeing Everything as an Object
  28 +
  29 +Initially, Matz looked at other languages to find an ideal syntax. Recalling his search, he said, "I wanted a scripting language that was more powerful than Perl, and more object-oriented than Python[3]."
  30 +
  31 +In Ruby, everything is an object. Every bit of information and code can be given their own properties and actions. Object-oriented programming calls properties by the name _instance variables_ and actions are known as _methods_. Ruby's pure object-oriented approach is most commonly demonstrated by a bit of code which applies an action to a number.
  32 +
  33 +<notextile><r:code>
  34 +5.times { print "We *love* Ruby -- it's outrageous!" }
  35 +</r:code></notextile>
  36 +
  37 +In many languages, numbers and other primitive types are not objects. Ruby follows the influence of the Smalltalk language by giving methods and instance variables to all of its types. This eases one's use of Ruby, since rules applying to objects apply to all of Ruby.
  38 +
  39 +h3. Ruby's Flexibility
  40 +
  41 +Ruby is seen as a flexible language, since it allows its users to freely alter its parts. Essential parts of Ruby can be removed or redefined, at will. Existing parts can be added upon. Ruby tries not to restrict the coder.
  42 +
  43 +For example, addition is performed with the plus (@+@) operator. But, if you'd rather use the readable word @plus@, you could add such a method to Ruby's builtin @Numeric@ class.
  44 +
  45 +<notextile><r:code>
  46 +class Numeric
  47 + def plus(x)
  48 + self.+(x)
  49 + end
  50 +end
  51 +
  52 +y = 5.plus 6
  53 +# y is now equal to 11
  54 +</r:code></notextile>
  55 +
  56 +Ruby's operators are syntactic sugar for methods. You can redefine them as well.
  57 +
  58 +h3. Blocks, a Truly Expressive Feature
  59 +
  60 +Ruby's block are also seen as a source of great flexibility. A programmer can attach a closure to any method, describing how that method should act. The closure is called a _block_ and has become one of the most popular features for newcomers to Ruby from other imperative languages like PHP or Visual Basic.
  61 +
  62 +Blocks are inspired by functional languages. Matz said, "in Ruby closures, I wanted to respect the Lisp culture[4]."
  63 +
  64 +<notextile><r:code>
  65 +search_engines =
  66 + %w[Google Yahoo MSN].map do |engine|
  67 + "http://www." + engine.downcase + ".com"
  68 + end
  69 +</r:code></notextile>
  70 +
  71 +In the above code, the block is described inside the @do ... end@ construct. The @map@ method applies the block to the provided list of words. Many other methods in Ruby leave a hole open for a coder to write their own block to fill in the details of what that method should do.
  72 +
  73 +h3. Ruby and the Mixin
  74 +
  75 +Unlike many object-oriented languages, Ruby features single inheritance only, *on purpose*. But Ruby knows the
  76 +concept of modules (called Categories in Objective-C). Modules are collections
  77 +of methods.
  78 +
  79 +Classes can mixin a module and receive all its methods for free. For example, any class which implements the @each@ method can mixin the @Enumerable@ module, which adds a pile of methods that use @each@ for looping.
  80 +
  81 +<notextile><r:code>
  82 +class MyArray
  83 + include Enumerable
  84 +end
  85 +</r:code></notextile>
  86 +
  87 +Generally, Rubyists see this as a much clearer way than multiple inheritance, which is complex and can be too restrictive.
  88 +
  89 +h3. Ruby's Visual Appearance
  90 +
  91 +While Ruby often uses very limited punctuation and usually prefers English keywords, some punctuation is used to decorate Ruby.
  92 +Ruby needs no variable declarations. It uses simple naming conventions to
  93 +denote the scope of variables.
  94 +
  95 +* @var@ could be a local variable.
  96 +* @@var@ is an instance variable.
  97 +* @$var@ is a global variable.
  98 +
  99 +These sigils enhance readability by allowing the programmer to easily identify the roles of each variable. It also becomes unnecessary to use a tiresome @self.@ prepended to every instance member.
  100 +
  101 +h3. Beyond the Basics
  102 +
  103 +Ruby has a wealth of other features, among which are the following:
  104 +
  105 +* Ruby has exception handling features, like Java or Python, to make it easy to
  106 +handle errors.
  107 +
  108 +* Ruby features a true mark-and-sweep garbage collector for all Ruby
  109 +objects. No need to maintain reference counts in extension
  110 +libraries. As Matz says, "This is better for your health."
  111 +
  112 +* Writing C extensions in Ruby is easier than in Perl or Python, with a very elegant
  113 +API for calling Ruby from C. This includes calls for embedding Ruby in software, for use
  114 +as a scripting language. A SWIG interface is also available.
  115 +
  116 +* Ruby can load extension libraries dynamically if an OS allows.
  117 +
  118 +* Ruby features OS independent threading. Thus, for all platforms on which Ruby
  119 +runs, you also have multithreading, regardless of if the OS supports it or not,
  120 +even on MS-DOS!
  121 +
  122 +* Ruby is highly portable: it is developed mostly on GNU/Linux, but works on many
  123 +types of UNIX, Mac OS X, Windows 95/98/Me/NT/2000/XP, DOS, BeOS, OS/2, etc.
  124 +
  125 +h4. References
  126 +
  127 +fn1. Matz, speaking on the Ruby-Talk mailing list, "May 12th, 2000":http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/2773.
  128 +
  129 +fn2. See the "Ruby on Rails":http://rubyonrails.org/ home page for more.
  130 +
  131 +fn3. Matz, in "An Interview with the Creator of Ruby":http://www.linuxdevcenter.com/pub/a/linux/2001/11/29/ruby.html, Nov. 29th, 2001.
  132 +
  133 +fn4. Matz, in "Blocks and Closures in Ruby":http://www.artima.com/intv/closures2.html, December 22nd, 2003.
129 about.zh_TW.textile
Source Rendered
... ... @@ -0,0 +1,129 @@
  1 +想知道Ruby為何如此受歡迎嗎? 為什麼它的支持者會稱它是個美麗、靈巧而且方便又實用的程式語言?
  2 +
  3 +h3. Ruby 發明者的理想
  4 +
  5 +!>{padding-left:8px}http://redhanded.hobix.com/images/ruby-lang-matz.png!
  6 +
  7 +Ruby 是一個注重均衡的語言. 它的發明者, <a href="http://www.rubyist.net/~matz/">松本行弘 Yukihiro "matz" Matsumoto</a>, 混合了他喜歡的語言 (如 Perl, Smalltalk, Eiffel, Ada, and Lisp) 產生了一個具有函數式與指令式程式設計語言特性的新語言。
  8 +
  9 +他常說他是: "試著讓 Ruby 更為自然,而不是簡單”,就像生活一樣。
  10 +
  11 +除此之外, 他還提到:
  12 +
  13 +bq. Ruby 就像人的身體一樣,表面上看來簡單,但是內在卻是相當的複雜,[1].
  14 +
  15 +h3. Ruby 的成長
  16 +
  17 +自從在 1995 年公開發表以來, Ruby 在全球吸引了許多忠實的程式設計師. 在 2006 年, Ruby 被廣泛的接受. 在各大城市都有活躍的使用者社群並舉辦了許許多多場場爆滿的研討會.
  18 +
  19 +!>{padding-left:8px}http://gmane.org/plot-rate.php?group=gmane.comp.lang.ruby.general&width=280&height=140&title=Ruby-Talk+Activity+over+4+Years(Graph courtesy of Gmane.)!
  20 +
  21 +在主要的 "郵件論壇: Ruby-Talk":/en/community/mailing-lists/ 上,討論 Ruby 語言的文章爬升到每日 200 封.
  22 +
  23 +在 "TIOBE 的最流行開發語言排名調查":http://www.tiobe.com/index.htm?tiobe_index中, Ruby 排名為全球第 11. 根據這樣的成長情況, 他們預測 "在半年之中 Ruby 將會進入最受歡迎的第 10 名." 有越來越多受歡迎的軟體如 Ruby on Rails web framework[2] 是使用 Ruby 撰寫而成,也是造成了 Ruby 如此的成長因素.
  24 +
  25 +同時,Ruby 是個"自由軟體":/zh_TW/about/license.txt. 不只是免費,而且可以自由的使用, 修改與散佈.
  26 +
  27 +h3. 所見即物件
  28 +
  29 +最初,Matz 從其他語言中找尋理想的語法。 想起他做的研究,他說:"我想要一個比 Perl 更強大,比 Python 更物件導向的 scripting language [3]".
  30 +
  31 +
  32 +在 Ruby 中,所有的東西都是個物件。所有的資訊與程式碼都可以給與他們所擁有的 屬性(properties) 與 行為(actions) 。物件導向程式設計中稱屬性為 _實體變數_(_instance variables_) 而行為稱為 _方法_(_methods_)。從下列程式碼中看到 Ruby 能夠給 "數字(number)" 賦予 "行為(actions)" 這特點來看,可以證明 Ruby 是個純物件導向的語言。
  33 +
  34 +
  35 +<notextile><r:code>
  36 +5.times { print "We *love* Ruby -- it's outrageous!" }
  37 +</r:code></notextile>
  38 +
  39 +在許多的語言中,數字與其他的原生資料型態(primitive types) 都不是物件。 而 Ruby 受到了 Smalltalk 語言讓所有的資料型態都可賦予方法與產生實體變數的影響。更進而讓這規則適用於 Ruby 中所有物件。
  40 +
  41 +
  42 +h3. Ruby 的彈性
  43 +
  44 +Ruby 是個相當具有彈性的語言, 它可以讓使用者自由的去改變它的本身。 Ruby 的必要部份也可以隨意地被移除或重新定義。已存在的部份也可以被繼續添加內容。Ruby 試著不去限制程式設計人員。
  45 +
  46 +
  47 +舉例而言,我們使用 (@+@) 運算元來執行加法。但是如果你打算使用 @plus@ 來取代,你可以加入以下的方法到 Ruby 的內建 @Numeric@ 類別之中。
  48 +
  49 +
  50 +<notextile><r:code>
  51 +class Numeric
  52 + def plus(x)
  53 + self.+(x)
  54 + end
  55 +end
  56 +
  57 +y = 5.plus 6
  58 +# y is now equal to 11
  59 +</r:code></notextile>
  60 +
  61 +Ruby 的運算元其實就是個方法(method)[4]。你也可以重新定義運算元。
  62 +
  63 +h3. 區塊(Blocks), 很有意思的功能
  64 +
  65 +Ruby 的區塊可說是它強大彈性的來源。 程式設計師可以為任何的 method 加上 closure(閉包) , 來描述這個 method 該做什麼。此處的 closure 稱為 _block_ 同時這也是從指令式程式設計語言如 PHP 或 Visual Basic 轉換到 Ruby 的新手最喜歡的功能。
  66 +
  67 +Block 的靈感是由函數式程式設計語言而來。Matz 說到:"在 Ruby closures 之中, 我要向 Lisp culture 致敬[5]."
  68 +
  69 +<notextile><r:code>
  70 +search_engines =
  71 + %w[Google Yahoo MSN].map do |engine|
  72 + "http://www." + engine.downcase + ".com"
  73 + end
  74 +</r:code></notextile>
  75 +
  76 +在上方的程式碼中,block 是在 @do ... end@ 之間。其中 @map@ method 提供一個字串陣列給 block。Ruby 中還有許多其他的 methods 提供了類似的方式可以讓程式設計師撰寫自己的 block 來完成此 method 該做的事。
  77 +
  78 +h3. Ruby 與 Mixin
  79 +
  80 +和其他許多的物件導向語言不同,Ruby 故意的只提供 單一繼承(single inheritance)。但是 Ruby 提供 模組(module) 的觀念(在 Objective-C 中稱為 Categories)。
  81 +Module 是許多 method 的集合。
  82 +
  83 +類別(Class) 可以 混入(mixin) 模組並且可以自由的取用模組內的所有方法。舉例而也,所有要實作 @each@ 方法的類別都可以 混入 @Enumerable@ 模組進來,就可以使用 @each@ 方法來達到執行迴圈的目的。
  84 +
  85 +<notextile><r:code>
  86 +class MyArray
  87 + include Enumerable
  88 +end
  89 +</r:code></notextile>
  90 +
  91 +一般來說,Ruby 使用者使用這種方式會比使用複雜且有很多限制的多重繼承來得清楚。
  92 +
  93 +h3. Ruby 的面貌
  94 +
  95 +Ruby 常使用某些符號與英文關鍵字來輔助撰寫程式。Ruby 不需要事先宣告變數。它使用簡單的命名規則來說明變數的生命範圍。
  96 +
  97 +* @var@ 表示變數是個 區域變數(local variable).
  98 +* @@var@ 表示變數是個 實體變數(instance variable).
  99 +* @$var@ 表示變數是個 全域變數(global variable).
  100 +
  101 +這些符號讓程式設計師可以輕易的定義每個變數的角色進而增加了程式的易讀性。另外 Ruby 也省略了累贅的 @self.@ 方便直接來存取每個實體成員。
  102 +
  103 +h3. 更上一層樓
  104 +
  105 +Ruby 還具有以下的特點:
  106 +
  107 +* Ruby 具有 例外處理(exception handling) 的能力。就如 Java 或 Python 一樣,可以讓使用者輕鬆的處理錯誤狀況。
  108 +
  109 +* Ruby 對於所有的物件具有一個真正的 標記-清除(mark and sweep) 式的垃圾收集器(garbage collector)。使用者不必去維護擴充函式庫中的 參考計數器(reference counts)。如 Matz說的:"這樣有益健康"。
  110 +
  111 +* 在 Ruby 中撰寫 C 的擴充程式比在 Perl 或 Python 中方便,它擁有許多方便的 API 可以讓 C 呼叫 Ruby。這樣可以將 Ruby 當成 script language 嵌入到其他軟體之中。它也具有 SWIG 的呼叫界面。
  112 +
  113 +* 如果作業系統支援,Ruby 可以動態的載入擴充函式庫。
  114 +
  115 +* Ruby 具有與作業系統無關的多緒(threading)能力。可以在所有可以執行 Ruby 的平台上都能夠達到多緒的目標,而不必管作業系統是否支援,就算是 MS-DOS 也行。
  116 +
  117 +* Ruby 具有高度的移植性:它大部份是在 GUN/Linux 上發展出來,但是可以執行於多種的作業系統如: UNIX, MAC OS X,Windows 95/98/Me/NT/2000/XP, DOS, BeOS, OS/2, 等等。
  118 +
  119 +h4. 參考資料
  120 +
  121 +fn1. Matz, 於 Ruby-Talk 郵件論壇上的發言, "May 12th, 2000":http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/2773.
  122 +
  123 +fn2. 請參考 "Ruby on Rails":http://rubyonrails.org/ 官方首頁有更多資料.
  124 +
  125 +fn3. Matz, in "An Interview with the Creator of Ruby":http://www.linuxdevcenter.com/pub/a/linux/2001/11/29/ruby.html, Nov. 29th, 2001.
  126 +
  127 +fn4. 原文直譯:運算元是方法的語法糖衣(syntactic sugar),Ruby's operators are syntactic sugar for methods.
  128 +
  129 +fn5. Matz, in "Blocks and Closures in Ruby":http://www.artima.com/intv/closures2.html, December 22nd, 2003.
31 community.conferences.textile
Source Rendered
... ... @@ -0,0 +1,31 @@
  1 +Ruby programmers around the world are getting involved in more and more conferences, where they get together to share reports on work-in-progress, discuss the future of Ruby, and welcome newcomers to the Ruby community.
  2 +
  3 +h3. Major Ruby Conferences
  4 +
  5 +<dl>
  6 +<dt>"RubyConf":http://rubyconf.org/</dt>
  7 +<dd>Every year since 2001, "Ruby Central, Inc.":http://www.rubycentral.org has produced RubyConf, the International Ruby conference. Attendance grew by a factor of ten between 2001 and 2006. RubyConf has provided a forum for presentations about Ruby technologies by their creators, including talks by Nathaniel Talbot on Test Unit, Jim Weirich on Rake, David Heinemeier Hansson on Ruby on Rails, Why the Lucky Stiff on the YAML library, and Sasada Koichi on YARV. Matz has attended, and spoken
  8 +at, all the RubyConfs but one.</dd>
  9 +
  10 +<dt>"RubyKaigi":http://jp.rubyist.net/RubyKaigi2008/</dt>
  11 +<dd>The first Japanese Ruby conference, RubyKaigi 2006, took place in Odaiba. RubyKaigi provides many new and exciting talks by Matz and other Rubyists in every year.</dd>
  12 +
  13 +<dt>"EuRuKo <small>(Europaeische Ruby Konferenz)</small>":http://www.approximity.com/cgi-bin/europeRuby/tiki.cgi?c=v&p=Euruko07</dt>
  14 +<dd>The first annual European Ruby Conference (EuRuKo) was held in Karlsruhe, Germany, in 2003. Organized by a team of German Rubyists including Armin Roehrl and Michael Neumann, EuRuKo emerged as the second annual Ruby event, starting two years after RubyConf.</dd>
  15 +
  16 +<dt>"Open Source Developer Conference":http://www.osdc.com.au/</dt>
  17 +<dd>This is an annual open source development conference that is held each year in Australia. While not specifically a Ruby conference, each year we do get a number of Ruby papers and we are always interested in more Ruby content.</dd>
  18 +</dl>
  19 +
  20 +h3. Regional Ruby Conferences
  21 +
  22 +"Ruby Central":http://www.rubycentral.org administers a "Regional Conference Grant Program":http://www.rubycentral.org/rcg2006.pdf, to offset expenses for local and regional groups wanting to organize events.</p>
  23 +
  24 +Ruby Central has also teamed up with "SDForum":http://www.sdforum.org to produce the Silicon Valley
  25 +Ruby Conference, entering its second year in 2007.
  26 +
  27 +"RubyNation":http://rubynation.org/ is an annual Ruby conference serving the Virginia, West Virginia, Maryland, and Washington, DC areas.
  28 +
  29 +h3. Ruby At Other Conferences
  30 +
  31 +There has been a Ruby track at the "O'Reilly Open Source Conference":http://conferences.oreillynet.com/os2006/ (OSCON) since 2004, and an increasing presence on the part of Ruby and Rubyists at other non-Ruby-specific gatherings. A number of conferences have also been devoted to "Ruby on Rails":http://www.rubyonrails.org, including Ruby Central's "RailsConf":http://www.railsconf.org, "RailsConf Europe":http://europe.railsconf.org (co-produced in 2006 by Ruby Central and "Skills Matter":http://www.skillsmatter.com, and in 2007 by Ruby Central and O'Reilly), and Canada on Rails.
76 community.ruby-core.textile
Source Rendered
... ... @@ -0,0 +1,76 @@
  1 +Now is a fantastic time to follow Ruby's development, with Ruby 2.0 development underway. With the increased attention Ruby has received in the past few years, there's a growing need for good talent to help enhance Ruby and document its parts. So, where do you start?
  2 +
  3 +The topics related to Ruby development covered here are:
  4 +
  5 +* "Using Subversion to Track Ruby Development":#following-ruby
  6 +* "How to Use Git With the Main Ruby Repository":#git-ruby
  7 +* "Improving Ruby, Patch by Patch":#patching-ruby
  8 +* and, "Rules for Core Developers":#coding-standards
  9 +
  10 +h3. <a name="following-ruby"></a>Using Subversion to Track Ruby Development
  11 +
  12 +Checking out the latest Ruby source code is a matter of logging into the "Subversion":http://subversion.tigris.org/ anonymous account. From your commandline:
  13 +
  14 +<code><pre>
  15 + $ svn co http://svn.ruby-lang.org/repos/ruby/trunk ruby
  16 +</pre></code>
  17 +
  18 +The @ruby@ directory will now contain the latest source code for Ruby 1.9 (trunk), which is the development version of Ruby. The trunk was used to release a stable 1.9.1 version in January 2009. Currently patches applied to the trunk are backported to the stable 1_9_1 branch (see below).
  19 +
  20 +If you'd like to follow patching of Ruby 1.9.1, you should use the @ruby_1_9_1@ branch when checking out:
  21 +
  22 +<code><pre>
  23 + $ svn co http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_1
  24 +</pre></code>
  25 +
  26 +If you'd like to follow patching of Ruby 1.8, you should use the @ruby_1_8_6@ or @ruby_1_8_7@ branch when checking out (depending on the version you're using):
  27 +
  28 +<code><pre>
  29 + $ svn co http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_7
  30 +</pre></code>
  31 +
  32 +This will check out the Ruby 1.8.7 development tree into a @ruby_1_8_7@ directory. Developers working on Ruby 1.8 are expected to migrate their changes to Ruby's trunk, so often the two branches are very similiar, with the exception of improvements made by Matz and Nobu to the language itself.
  33 +
  34 +If you prefer, you may browse "Ruby's repository via the web":http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/.
  35 +
  36 +For information about Subversion, please see "the Subversion FAQ":http://subversion.tigris.org/faq.html and "the Subversion book":http://svnbook.org. Alternatively, you may find "Pragmatic Version Control with Subversion":http://www.pragmaticprogrammer.com/titles/svn/ to be a useful introductory book.
  37 +
  38 +h3. <a name="git-ruby"></a>How to Use Git With the Main Ruby Repository
  39 +
  40 +Those who prefer to use "Git":http://git-scm.com/ over Subversion can find instructions with "the mirror on GitHub":http://github.com/shyouhei/ruby, both for "those with commit access":http://wiki.github.com/shyouhei/ruby/committerhowto and "everybody else":http://wiki.github.com/shyouhei/ruby/noncommitterhowto.
  41 +
  42 +h3. <a name="patching-ruby"></a>Improving Ruby, Patch by Patch
  43 +
  44 +The core team maintains "a bug tracker":http://redmine.ruby-lang.org/ for submitting patches and bug reports to Matz and the gang. These reports also get submitted to the "Ruby-Core mailing list":/en/community/mailing-lists/#ruby-core for discussion, so you can be sure your request won't go unnoticed. You can also send your patches straight to the mailing list. Either way, you are encouraged to take part in the discussion that ensues.
  45 +
  46 +Please look over the "Patch Writer's Guide":http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/25139 for some tips, straight from matz, on how to get your patches considered.
  47 +
  48 +To summarize, the steps for building a patch are:
  49 +
  50 +# If you are fixing a bug in Ruby 1.8, check out a copy of Ruby 1.8 from Subversion using the @ruby_1_8@ branch.<code><pre>
  51 + $ svn co http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8
  52 +</code></pre>If you wish to add a feature to Ruby, check out the trunk of Ruby's source. Even if you wish to add a feature to Ruby 1.8, it has to be proven in the trunk first.<code><pre>
  53 + $ svn co http://svn.ruby-lang.org/repos/ruby/trunk ruby
  54 +</code></pre>
  55 +# Add your improvements to the code.
  56 +# Create a patch.<code><pre>
  57 + $ svn diff > ruby-changes.patch
  58 +</pre></code>
  59 +# Email your patch to the "Ruby-Core mailing list":/en/community/mailing-lists/#ruby-core with a CHANGELOG entry describing the patch.
  60 +# If there are no issues raised about the patch, committers will be given the approval to apply it.
  61 +
  62 +*Please note:* patches should be submitted as a "unified diff":http://www.gnu.org/software/diffutils/manual/html_node/Unified-Format.html. For more on how patches are merged, see "the diffutils reference":http://www.gnu.org/software/diffutils/manual/html_node/Merging-with-patch.html#Merging%20with%20patch.
  63 +
  64 +Discussion of Ruby's development converges on the "Ruby-Core mailing list":/en/community/mailing-lists/#ruby-core. So, if you are curious about whether your patch is worthwhile or you want to spark a discussion about Ruby's future, don't hesitate to come aboard. Be warned that off-topic discussions are not tolerated on this list, the noise level should be very low, topics should be pointed, well-conceived and well-written. Since we're addressing Ruby's creator, let's have some reverence.
  65 +
  66 +Keep in mind that Ruby's core developers live in Japan and, while many speak very good English, there is a significant timezone difference. They also have an entire body of Japanese development lists happening alongside the English counterparts. Be patient, if your claim isn't resolved, be persistent -- give it another shot a few days later.
  67 +
  68 +h3. <a name="coding-standards"></a>Rules for Core Developers
  69 +
  70 +Generally, the developers of Ruby should be familiar with the source code and the style of development used by the team. To be clear, the following guidelines should be honored when checking into Subversion:
  71 +
  72 +* All check-ins should be described in the @ChangeLog@, following the "GNU conventions":http://www.gnu.org/prep/standards/standards.html#Change-Logs. (Many Ruby core developers use Emacs @add-log@ mode, which can be accessed with the command @C-x 4 a@.)
  73 +* Check-in dates should be given in Japan Standard Time (UTC+9).
  74 +* The bulleted points from your ChangeLog should also be placed in the Subversion commit message. This message will be automatically mailed to the Ruby-CVS list after you commit.
  75 +* K&R function declarations are used throughout Ruby's source code and its packaged extensions.
  76 +* Please, do not use C++-style comments (@//@), Ruby's maintainers instead prefer the standard C multiline comment. (@/* .. */@)
36 community.textile
Source Rendered
... ... @@ -0,0 +1,36 @@
  1 +The community that grows up around a programming language is one of its most important strengths. Ruby has a vibrant and growing community that is friendly towards people of all skill levels.
  2 +
  3 +If you are interested in getting involved, here are a couple of places to start:
  4 +
  5 +<dl>
  6 +<dt>"Ruby User Groups":user-groups/</dt>
  7 +<dd>Your local Ruby user group is a great place to network with other Ruby programmers. Ruby user groups are self-organizing and typically feature monthly meetings, a mailing list, a Web site, and if you are lucky, frequent codefests.</dd>
  8 +
  9 +<dt>"Ruby Mailing Lists and Newsgroups":mailing-lists/</dt>
  10 +<dd>Ruby has an assortment of lists on different topics and in several languages. If you have questions about Ruby, asking them on a mailing list is a great way to get answers.</dd>
  11 +
  12 +<dt>"Ruby on IRC":irc://irc.freenode.net/ruby-lang</dt>
  13 +<dd>The Ruby Language IRC Channel is a wonderful way to chat with fellow Rubyists. ("Previous Chat Logs":http://meme.b9.com/)
  14 +</dd>
  15 +
  16 +<dt>"Ruby Core":ruby-core/</dt>
  17 +<dd>With Ruby 2.0 underway, now is a fantastic time to be following Ruby's development. If you are interested in helping with Ruby, start here.</dd>
  18 +
  19 +<dt>"Weblogs About Ruby":weblogs/</dt>
  20 +<dd>Very little happens in the Ruby community that is not talked about on the blogs. We've got a nice list of suggestions for you here for getting plugged in.</dd>
  21 +
  22 +<dt>"Ruby Conferences":conferences/</dt>
  23 +<dd>Ruby programmers around the world are getting involved in more and more conferences, where they get together to share reports on work-in-progress, discuss the future of Ruby, and welcome newcomers to the Ruby community.</dd>
  24 +
  25 +<dt>"The Ruby Mentor Project":http://rubymentor.rubyforge.org/</dt>
  26 +<dd>This new resource aims to pair people new to Ruby with more experienced guides. The goal is to ease the process of learning Ruby by having someone you can ask questions of. This is intended to be a little less intimidating than a mailing list, though Ruby Talk does welcome questions from beginners.</dd>
  27 +
  28 +<dt>General Ruby Information</dt>
  29 +<dd>
  30 +<ul>
  31 +<li>"Ruby Central":http://www.rubycentral.org/</li>
  32 +<li>"Ruby at Open Directory Project":http://dmoz.org/Computers/Programming/Languages/Ruby/</li>
  33 +<li>"Rails at Open Directory Project":http://dmoz.org/Computers/Programming/Languages/Ruby/Software/Rails/</li>
  34 +</ul>
  35 +</dd>
  36 +</dl>
32 community.weblogs.textile
Source Rendered
... ... @@ -0,0 +1,32 @@
  1 +Ruby blogs have exploded over the past year and, given sufficient hunting, you can unearth hundreds of blogs sharing bits of Ruby code, describing new techniques, or speculating on Ruby's future.
  2 +
  3 +h3. Mining for Ruby Blogs
  4 +
  5 +"*Ruby on del.icio.us*":http://del.icio.us/tag/ruby: Ruby and Rails are consistently one of the top fifty tags on del.icio.us, a popular link sharing site. Watch the "ruby":http://del.icio.us/tag/ruby tag for incoming obscure links and its "popularity chart":http://del.icio.us/popular/ruby for recent upcomers in the Ruby community.
  6 +
  7 +!>http://technorati.com/chartimg/%28ruby%29?totalHits=391174&size=s&days=30(30-day graph of activity for 'ruby' among blogs on Technorati.)!
  8 +
  9 +"*Ruby on Technorati*":http://technorati.com/search/ruby: Technorati's search for _"Ruby"_ yields the most recent posts across the blogs covered in its index.
  10 +
  11 +*Planets*: some planets (online specialized feeds agregators) have been running for years now. A few of them providing convenient content:
  12 +* "Ruby Corner":http://rubycorner.com
  13 +* "Planet Ruby":http://planetruby.0x42.net/
  14 +* "PlanetRubyOnRails.org":http://www.planetrubyonrails.org/
  15 +* "PlanetRubyOnRails.com":http://www.planetrubyonrails.com/
  16 +
  17 +h3. Blogs of Note
  18 +
  19 +A few notable blogs stand out for the frequency and immediacy of their updates.
  20 +
  21 +* "*O'Reilly Ruby*":http://oreillynet.com/ruby/ is a group blog with pertinent Ruby tutorials and interviews with interesting folks from around the community.
  22 +* "*Riding Rails*":http://weblog.rubyonrails.org/ is the official group blog of the Ruby on Rails team. If you are running Rails, this blog is essential for notification of security updates and an overall view of the wide Rails community.
  23 +* "*Ruby Inside*":http://www.rubyinside.com/ announces interesting applications and libraries from throughout the world, both Ruby and Rails.
  24 +* "*Matz' Blog*":http://www.rubyist.net/~matz/ is a Japanese blog written by Ruby's creator. Even if you can't read all of it, it's good to know he's right there!
  25 +* "*Rails Envy*":http://railsenvy.com/ is a blog and podcast where you can learn a lot about what's going on in Rails and just plain Ruby. They have a good video collection too, where you can fast-forward through popular Ruby events or just be entertained.
  26 +* "*Ruby Web Developer news group*":http://newsforwhatyoudo.com/groups/643ddee01cd911deaef1001aa018681c/news is a new type of collaborative news site / feed reader where Rubyists discover, filter and comment on news that's relevant to their profession.
  27 +
  28 +h3. Spreading the Word
  29 +
  30 +If you've got a Ruby blog you've started, it's wise to link the blog on "del.icio.us":http://del.icio.us with the _ruby_ tag. You might also contact the weblogs above, if you are covering a topic they'd be interested in. (Obviously, if it's not Rails-related, then the _Riding Rails_ crew may not be as interested -- but you never know.)
  31 +
  32 +Ruby is also a common topic on both "Digg":http://digg.com/programming and "Slashdot":http://developers.slashdot.org/, in their respective programming news. If you find some brilliant code out there, be sure to let them know!
118 documentation.quickstart.textile
Source Rendered
... ... @@ -0,0 +1,118 @@
  1 +h2. Introduction
  2 +
  3 +This is a small Ruby tutorial that should take no more than 20 minutes to
  4 +complete. It makes the assumption that you already have Ruby installed.
  5 +(If you don't have Ruby on your computer "download":/en/downloads/ and
  6 +install it before you get started.)
  7 +
  8 +h2. Interactive Ruby
  9 +
  10 +Ruby comes with a program that will show the results of any Ruby statements you feed it. Playing with Ruby code in interactive sessions like this is a terrific way to learn the language.
  11 +
  12 +Open up IRB (which stands for Interactive Ruby).
  13 +
  14 +* If you're using *Mac OS X* open up @Terminal@ and type
  15 +@irb@, then hit enter.
  16 +* If you're using *Linux*, open up a shell and type
  17 +@irb@ and hit enter.
  18 +* If you're using *Windows*, open @fxri@ from the Ruby section of your Start Menu.
  19 +
  20 +<notextile><r:code>
  21 +irb(main):001:0>
  22 +</r:code></notextile>
  23 +
  24 +Ok, so it's open. Now what?
  25 +
  26 +Type this: @"Hello World"@
  27 +
  28 +<notextile><r:code>
  29 +irb(main):001:0> "Hello World"
  30 +=> "Hello World"
  31 +</r:code></notextile>
  32 +
  33 +h2. Ruby Obeyed You!
  34 +
  35 +What just happened? Did we just write the world's shortest "Hello
  36 +World" program? Not exactly. The second line is just IRB's way of
  37 +telling us the result of the last expression it evaluated. If we want
  38 +to print out "Hello World" we need a bit more:
  39 +
  40 +<notextile><r:code>
  41 +irb(main):002:0> puts "Hello World"
  42 +Hello World
  43 +=> nil
  44 +</r:code></notextile>
  45 +
  46 +@puts@ is the basic command to print something out in Ruby. But then what's the
  47 +@=> nil@ bit? That's the result of the expression. @puts@ always
  48 +returns nil, which is Ruby's absolutely-positively-nothing value.
  49 +
  50 +h2. Your Free Calculator is Here
  51 +
  52 +Already, we have enough to use IRB as a basic calculator:
  53 +
  54 +<notextile><r:code>
  55 +irb(main):003:0> 3+2
  56 +=> 5
  57 +</r:code></notextile>
  58 +
  59 +Three plus two. Easy enough. What about three _times_ two? You could
  60 +type it in, it's short enough, but you may also be able to go up and
  61 +change what you just entered. Try hitting the *up-arrow* on your
  62 +keyboard and see if it brings up the line with @3+2@ on it. If it
  63 +does, you can use the left arrow key to move just after the @+@ sign
  64 +and then use backspace to change it to a @*@ sign.
  65 +
  66 +<notextile><r:code>
  67 +irb(main):004:0> 3*2
  68 +=> 6
  69 +</r:code></notextile>
  70 +
  71 +Next, let's try three squared:
  72 +
  73 +<notextile><r:code>
  74 +irb(main):005:0> 3**2
  75 +=> 9
  76 +</r:code></notextile>
  77 +
  78 +In Ruby @**@ is the way you say "to the power of". But what if you
  79 +want to go the other way and find the square root of something?
  80 +
  81 +<notextile><r:code>
  82 +irb(main):006:0> Math.sqrt(9)
  83 +=> 3.0
  84 +</r:code></notextile>
  85 +
  86 +Ok, wait, what was that last one? If you guessed, "it was figuring out
  87 +the square root of nine," you're right. But let's take a closer
  88 +look at things. First of all, what's @Math@?
  89 +
  90 +h2. Modules, Group Code by Topic
  91 +
  92 +@Math@ is a built-in module for mathematics. Modules serve two roles in
  93 +Ruby. This shows one role: grouping similar methods together under a familiar
  94 +name. @Math@ also contains methods like @sin()@ and @tan()@.
  95 +
  96 +Next is a dot. What does the dot do? The dot is how you identify the
  97 +receiver of a message. What's the message? In this case it's
  98 +@sqrt(9)@, which means call the method @sqrt@, shorthand for "square
  99 +root" with the parameter of @9@.
  100 +
  101 +The result of this method call is the value @3.0@. You might notice
  102 +it's not just @3@. That's because most of the time the square root of
  103 +a number won't be an integer, so the method always returns a
  104 +floating-point number.
  105 +
  106 +What if we want to remember the result of some of this math? Assign
  107 +the result to a variable.
  108 +
  109 +<notextile><r:code>
  110 +irb(main):007:0> a = 3 ** 2
  111 +=> 9
  112 +irb(main):008:0> b = 4 ** 2
  113 +=> 16
  114 +irb(main):009:0> Math.sqrt(a+b) => 5.0
  115 +</r:code></notextile>
  116 +
  117 +As great as this is for a calculator, we’re getting away from the traditional
  118 +@Hello World@ message that beginning tutorials are supposed to focus on… "so let’s go back to that.":2/
429 documentation.ruby-from-other-languages.textile
Source Rendered
... ... @@ -0,0 +1,429 @@
  1 +When you first look at some Ruby code, it will likely remind you of other
  2 +programming languages you've used. This is on purpose. Much of the
  3 +syntax is familiar to users of Perl, Python, and Java (among other
  4 +languages), so if you've used those, learning Ruby will be a piece of cake.
  5 +
  6 +This document contains two major sections. The first attempts
  7 +to be a rapid-fire summary of what you can expect to see when going
  8 +from language _X_ to Ruby. The second section tackles the major
  9 +language features and how they might compare to what you're already
  10 +familiar with.
  11 +
  12 +h2. What to Expect: _Language X_ to Ruby
  13 +<r:children:each by="title">
  14 +* <r:link /></r:children:each>
  15 +
  16 +h2. Important Language Features And Some Gotchas
  17 +
  18 +Here are some pointers and hints on major Ruby features you'll
  19 +see while learning Ruby.
  20 +
  21 +h3. Iteration
  22 +
  23 +Two Ruby features that are a bit unlike what you may have seen before,
  24 +and which take some getting used to, are "blocks" and iterators. Instead
  25 +of looping over an index (like with C, C++, or pre-1.5 Java),
  26 +or looping over a list (like Perl's <tt>for (@a) {...}</tt>, or Python's
  27 +<tt>for i in aList: ...</tt>), with Ruby you'll very often instead see
  28 +
  29 +<notextile><r:code>
  30 +some_list.each do |this_item|
  31 + # We're inside the block.
  32 + # deal with this_item.
  33 +end
  34 +</r:code></notextile>
  35 +
  36 +For more info on @each@ (and it's friends @collect@, @find@, @inject@, @sort@, etc.),
  37 +see @ri Enumerable@ (and then <tt>ri Enumerable#<i>func_name</i></tt>).
  38 +
  39 +h3. Everything has a value
  40 +
  41 +There's no difference between an expression and a statement. Everything has a value,
  42 +even if that value is *nil*. This is possible:
  43 +
  44 +<notextile><r:code>
  45 +x = 10
  46 +y = 11
  47 +z = if x < y
  48 + true
  49 +else
  50 + false
  51 +end
  52 +z # => true
  53 +</r:code></notextile>
  54 +
  55 +h3. Symbols are not lightweight Strings
  56 +
  57 +Many Ruby newbies struggle with understanding what Symbols are, and what they can
  58 +be used for.
  59 +
  60 +Symbols can best be described as identities. A symbol is all about *who* it is,
  61 +not *what* it is. Fire up <code>irb</code> and see the difference:
  62 +
  63 +<notextile><r:code>
  64 +irb(main):001:0> :george.object_id == :george.object_id
  65 +=> true
  66 +irb(main):002:0> "george".object_id == "george".object_id
  67 +=> false
  68 +irb(main):003:0>
  69 +</r:code></notextile>
  70 +
  71 +The <code>object_id</code> methods returns the identity of an Object. If two
  72 +objects have the same <code>object_id</code>, they are the same (point to the
  73 +same Object in memory).
  74 +
  75 +As you can see, once you have used a Symbol once, any Symbol with the same
  76 +characters references the same Object in memory. For any given two Symbols that
  77 +represent the same characters, the <code>object_id</code>s match.
  78 +
  79 +Now take a look at the String ("george"). The <code>object_id</code>s don't
  80 +match. That means they're referencing two different objects in memory.
  81 +Whenever you use a new String, Ruby allocates memory for it.
  82 +
  83 +If you're in doubt whether to use a Symbol or a String, consider what's more
  84 +important: the identity of an object (i.e. a Hash key), or the contents (in
  85 +the example above, "george").
  86 +
  87 +
  88 +h3. Everything is an Object
  89 +
  90 +"Everything is an object" isn't just hyperbole. Even classes and integers are
  91 +objects, and you can do the same things with them as with any other object:
  92 +
  93 +<notextile><r:code>
  94 +# This is the same as
  95 +# class MyClass
  96 +# attr_accessor :instance_var
  97 +# end
  98 +MyClass = Class.new do
  99 + attr_accessor :instance_var
  100 +end
  101 +</r:code></notextile>
  102 +
  103 +
  104 +h3. Variable Constants
  105 +
  106 +Constants are not really constant. If you modify an already initialized constant,
  107 +it will trigger a warning, but not halt your program. That isn't to say you
  108 +*should* redefine constants, though.
  109 +
  110 +
  111 +
  112 +h3. Naming conventions
  113 +
  114 +Ruby enforces some naming conventions. If an identifier starts with a capital letter,
  115 +it is a constant. If it starts with a dollar sign ($), it is a global variable. If
  116 +it starts with <code>@</code>, it is an instance variable. If it starts with <code>@@</code>,
  117 +it is a class variable.
  118 +
  119 +Method names, however, are allowed to start with capital letters. This can lead to
  120 +confusion, as the example below shows:
  121 +
  122 +<notextile><r:code>
  123 +Constant = 10
  124 +def Constant
  125 + 11
  126 +end
  127 +</r:code></notextile>
  128 +
  129 +Now <code>Constant</code> is 10, but <code>Constant()</code> is 11.
  130 +
  131 +
  132 +
  133 +h3. Fake keyword parameters
  134 +
  135 +Ruby doesn't have keyword parameters, like Python has. However, it can be faked by
  136 +using symbols and hashes. Ruby on Rails, among others, uses this heavily. Example:
  137 +
  138 +<notextile><r:code>
  139 +def some_keyword_params( params )
  140 + params
  141 +end
  142 +some_keyword_params( :param_one => 10, :param_two => 42 )
  143 +# => {:param_one=>10, :param_two=>42}
  144 +</r:code></notextile>
  145 +
  146 +h3. The universal truth
  147 +
  148 +In Ruby, everything except *nil* and *false* is considered true. In C, Python and
  149 +many other languages, 0 and possibly other values, such as empty lists, are consided
  150 +false. Take a look at the following Python code (the example applies to other languages,
  151 +too):
  152 +
  153 +<notextile><r:code>
  154 +# in Python
  155 +if 0:
  156 + print "0 is true"
  157 +else:
  158 + print "0 is false"
  159 +</r:code></notextile>
  160 +
  161 +This will print "0 is false". The equivalent Ruby:
  162 +
  163 +<notextile><r:code>
  164 +# in Ruby
  165 +if 0
  166 + puts "0 is true"
  167 +else
  168 + puts "0 is false"
  169 +end
  170 +</r:code></notextile>
  171 +
  172 +Prints "0 is true".
  173 +
  174 +
  175 +
  176 +h3. Access modifiers apply until the end of scope
  177 +
  178 +In the following Ruby code,
  179 +
  180 +<notextile><r:code>
  181 +class MyClass
  182 + private
  183 + def a_method; true; end
  184 + def another_method; false; end
  185 +end
  186 +</r:code></notextile>
  187 +
  188 +You might expect <code>another_method</code> to be public. Not so. The 'private' access
  189 +modifier continues until the end of the scope, or until another access modifier
  190 +pops up, whichever comes first. By default, methods are public:
  191 +
  192 +<notextile><r:code>
  193 +class MyClass
  194 + # Now a_method is public
  195 + def a_method; true; end
  196 +
  197 + private
  198 +
  199 + # another_method is private
  200 + def another_method; false; end
  201 +end
  202 +</r:code></notextile>
  203 +
  204 +<code>public</code>, <code>private</code> and <code>protected</code> are really methods,
  205 +so they can take parameters. If you pass a Symbol to one of them, that method's visibility
  206 +is altered.
  207 +
  208 +
  209 +
  210 +h3. Method access
  211 +
  212 +<p>In Java, <code>public</code> means a method is accessible by anyone. <code>protected</code>
  213 +means the class's instances, instances of descendant classes, and instances of classes in the same package
  214 +can access it, but not anyone else, and <code>private</code> means nobody besides the classes instances
  215 +can access the method.</p>
  216 +
  217 +Ruby differs slightly. <code>public</code> is, naturally, public. <code>private</code> means
  218 +the method(s) are accessible only when they can be called without an explicit receiver. Only *self* is
  219 +allowed to be the receiver of a private method call.
  220 +
  221 +<code>protected</code> is the one to be on the lookout for. A protected method can be called
  222 +from a class or descendant class instances, but also with another instance as its receiver.
  223 +
  224 +Example, adapted from the "Ruby FAQ":http://faq.rubygarden.org/entry/show/57?controller_prefix=faq%2F:
  225 +
  226 +<notextile><r:code>
  227 +$ irb
  228 +irb(main):001:0> class Test
  229 +irb(main):002:1> # public by default
  230 +irb(main):003:1* def func
  231 +irb(main):004:2> 99
  232 +irb(main):005:2> end
  233 +irb(main):006:1>
  234 +irb(main):007:1* def ==(other)
  235 +irb(main):008:2> func == other.func
  236 +irb(main):009:2> end
  237 +irb(main):010:1> end
  238 +=> nil
  239 +irb(main):011:0>
  240 +irb(main):012:0* t1 = Test.new
  241 +=> #<Test:0x34ab50>
  242 +irb(main):013:0> t2 = Test.new
  243 +=> #<Test:0x342784>
  244 +irb(main):014:0> t1 == t2
  245 +=> true
  246 +irb(main):015:0> # now make `func` protected, still works
  247 +irb(main):016:0* # because protected allows the other reference
  248 +irb(main):017:0* class Test
  249 +irb(main):018:1> protected :func
  250 +irb(main):019:1> end
  251 +=> Test
  252 +irb(main):020:0> t1 == t2
  253 +=> true
  254 +irb(main):021:0> # now make `func` private
  255 +irb(main):022:0* class Test
  256 +irb(main):023:1> private :func
  257 +irb(main):024:1> end
  258 +=> Test
  259 +irb(main):025:0> t1 == t2
  260 +NoMethodError: private method `func' called for #<Test:0x342784>
  261 + from (irb):8:in `=='
  262 + from (irb):25
  263 + from :0
  264 +irb(main):026:0>
  265 +</r:code></notextile>
  266 +
  267 +
  268 +
  269 +h3. Classes are open
  270 +
  271 +Ruby classes are open. You can open them up, add to them, and change them
  272 +at any time. Even core classes, like <code>Fixnum</code> or even
  273 +<code>Object</code>, the parent of all objects. Ruby on Rails defines a
  274 +bunch of methods for dealing with time on <code>Fixnum</code>. Watch:
  275 +
  276 +<notextile><r:code>
  277 +class Fixnum
  278 + def hours
  279 + self * 3600 # number of seconds in an hour
  280 + end
  281 + alias hour hours
  282 +end
  283 +
  284 +# 14 hours from 00:00 January 1st
  285 +# (aka when you finally wake up ;)
  286 +Time.mktime(2006, 01, 01) + 14.hours # => Sun Jan 01 14:00:00
  287 +</r:code></notextile>
  288 +
  289 +
  290 +
  291 +h3. Funny method names
  292 +
  293 +In Ruby, methods are allowed to end with question marks or exclamation marks.
  294 +By convention, methods that answer questions (i.e. <tt>Array#empty?</tt>
  295 +returns *true* if the receiver is empty) end in question marks. Potentially
  296 +"dangerous" methods (ie methods that modify *self* or the arguments,
  297 +<code>exit!</code> etc.) by convention end with exclamation marks.
  298 +
  299 +All methods that change their arguments don't end with exclamation marks,
  300 +though. <tt>Array#replace</tt> replaces the contents of an array with the contents
  301 +of another array. It doesn't make much sense to have a method like that
  302 +that *doesn't* modify self.
  303 +
  304 +
  305 +
  306 +h3. Singleton methods
  307 +
  308 +Singleton methods are per-object methods. They are only available on the
  309 +Object you defined it on.
  310 +
  311 +<notextile><r:code>
  312 +class Car
  313 + def inspect
  314 + "Cheap car"
  315 + end
  316 +end
  317 +
  318 +porsche = Car.new
  319 +porsche.inspect # => Cheap car
  320 +def porsche.inspect
  321 + "Expensive car"
  322 +end
  323 +
  324 +porsche.inspect # => Expensive car
  325 +
  326 +# Other objects are not affected
  327 +other_car = Car.new
  328 +other_car.inspect # => Cheap car
  329 +</r:code></notextile>
  330 +
  331 +
  332 +h3. Missing methods
  333 +
  334 +Ruby doesn't give up if it can't find a method that responds to a particular
  335 +message. It calls the <code>method_missing</code> method with the name of the method
  336 +it couldn't find and the arguments. By default, method_missing raises a
  337 +NameError exception, but you can redefine it to better fit your application,
  338 +and many libraries do. Here is an example:
  339 +
  340 +<notextile><r:code>
  341 +# id is the name of the method called, the * syntax collects
  342 +# all the arguments in an array named 'arguments'
  343 +def method_missing( id, *arguments )
  344 + puts "Method #{id} was called, but not found. It has " +
  345 + "these arguments: #{arguments.join(", ")}"
  346 +end
  347 +
  348 +__ :a, :b, 10
  349 +# => Method __ was called, but not found. It has these
  350 +# arguments: a, b, 10
  351 +</r:code></notextile>
  352 +
  353 +The code above just prints the details of the call, but you are free to handle the message in any way that is appropriate.
  354 +
  355 +
  356 +
  357 +h3. Message passing, not function calls
  358 +
  359 +A method call is really a *message* to another object:
  360 +
  361 +<notextile><r:code>
  362 +# This
  363 +1 + 2
  364 +# Is the same as this ...
  365 +1.+(2)
  366 +# Which is the same as this:
  367 +1.send "+", 2
  368 +</r:code></notextile>
  369 +
  370 +h3. Blocks are Objects, they just don't know it yet
  371 +
  372 +Blocks (closures, really) are heavily used by the standard library. To call a
  373 +block, you can either use @yield@, or make it a @Proc@ by appending a special
  374 +argument to the argument list, like so:
  375 +
  376 +<notextile><r:code>
  377 +def block( &the_block )
  378 + # Inside here, the_block is the block passed to the method
  379 + the_block # return the block
  380 +end
  381 +adder = block { |a, b| a + b }
  382 +# adder is now a Proc object
  383 +adder.class # => Proc
  384 +</r:code></notextile>
  385 +
  386 +You can create blocks outside of method calls, too, by calling Proc.new with
  387 +a block or calling the <code>lambda</code> method.
  388 +
  389 +Similarly, methods are also Objects in the making:
  390 +
  391 +<notextile><r:code>
  392 +method(:puts).call "puts is an object!"
  393 +# => puts is an object!
  394 +</r:code></notextile>
  395 +
  396 +h3. Operators are syntactic sugar
  397 +
  398 +Most operators in Ruby are just syntactic sugar (with some precedence rules) for method calls. You can, for example, override Fixnums + method:
  399 +
  400 +<notextile><r:code>
  401 +class Fixnum
  402 + # You can, but please don't do this
  403 + def +( other )
  404 + self - other
  405 + end
  406 +end
  407 +</r:code></notextile>
  408 +
  409 +You don't need C++'s <code>operator+</code>, etc.
  410 +
  411 +You can even have array-style access if you define the <code>[]</code> and <code>[]=</code>
  412 +methods. To define the unary + and - (think +1 and -2), you must define the
  413 +<code>+@</code> and <code>-@</code> methods, respectively.
  414 +
  415 +The operators below are *not* syntactic sugar, though. They are not methods,
  416 +and cannot be redefined:
  417 +
  418 +<notextile><r:code lang="symbols">
  419 +=, .., ..., !, not, &&, and, ||, or, !=, !~, ::
  420 +</r:code></notextile>
  421 +
  422 +In addition, +=, *= etc. are just abbrevations for
  423 +<code>var = var + other_var</code>, <code>var = var * other_var</code>, etc. and therefore
  424 +cannot be redefined.
  425 +
  426 +
  427 +h2. Finding Out More
  428 +
  429 +When you are ready for more Ruby knowledge, see our "Documentation":/en/documentation/ section.
148 documentation.ruby-from-other-languages.to-ruby-from-c-and-c-.textile
Source Rendered
... ... @@ -0,0 +1,148 @@
  1 +It's difficult to write a bulleted list describing how your code
  2 +will be different in Ruby from C or C++ because it's quite a large
  3 +difference. One reason is that the Ruby runtime does so much for you.
  4 +Ruby seems about as far as you can get from C's "no hidden mechanism"
  5 +principle -- the whole point of Ruby is to make the human's job easier
  6 +at the expense of making the runtime shoulder more of the work. Unless
  7 +or until you profile your code for optimization, you don't need to
  8 +care one whit about "keeping your compiler happy" when using Ruby.
  9 +
  10 +That said, for one thing, you can expect your Ruby code to execute
  11 +much more slowly than "equivalent" C or C++ code. At the same time,
  12 +your head will spin at how rapidly you can get a Ruby program up and
  13 +running, as well as at how few lines of code it will take to write it.
  14 +Ruby is much much simpler than C++ -- it will spoil you rotten.
  15 +
  16 +Ruby is dynamically typed, rather than statically typed -- the
  17 +runtime does as much as possible at run-time. For example, you don't
  18 +need to know what modules your Ruby program will "link to" (that is,
  19 +load and use) or what methods it will call ahead of time.
  20 +
  21 +Happily, it turns out that Ruby and C have a healthy symbiotic
  22 +relationship. Ruby supports so-called "extension modules". These
  23 +are modules that you can use from your Ruby programs (and which,
  24 +from the outside, will look and act just like any other Ruby module),
  25 +but which are written in C. In this way, you can compartmentalize the
  26 +performance-critical parts of your Ruby software, and smelt
  27 +those down to pure C.
  28 +
  29 +And, of course, Ruby itself is written in C.
  30 +
  31 +
  32 +
  33 +h3. Similarities with C
  34 +
  35 +As with C, in Ruby,...
  36 +* You may program procedurally if you like (but it will still
  37 +be object-oriented behind the scenes).
  38 +* Most of the operators are the same (including the compound
  39 +assignment and also bitwise operators). Though, Ruby doesn't
  40 +have @++@ or @--@.
  41 +* You've got @__FILE__@ and @__LINE__@.
  42 +* You can also have constants, though there's no special @const@
  43 +keyword. Const-ness is enforced by a naming convention instead --
  44 +names starting with a capital letter are for constants.
  45 +* Strings go in double-quotes.
  46 +* Strings are mutable.
  47 +* Just like man pages, you can read most docs in your
  48 +terminal window -- though using the @ri@ command.
  49 +* You've got the same sort of command-line debugger available.
  50 +
  51 +
  52 +
  53 +h3. Similarities with C++
  54 +
  55 +As with C++, in Ruby,...
  56 +* You've got mostly the same operators (even @::@). @<<@ is often used
  57 +for appending elements to a list. One note though: with Ruby you never
  58 +use @->@ -- it's always just @.@.
  59 +* @public@, @private@, and @protected@ do similar jobs.
  60 +* Inheritance syntax is still only one character, but it's @<@
  61 +instead of @:@.
  62 +* You may put your code into "modules", similar to how @namespace@
  63 +in C++ is used.
  64 +* Exceptions work in a similar manner, though the keyword names have
  65 +been changed to protect the innocent.
  66 +
  67 +
  68 +
  69 +h3. Differences from C
  70 +
  71 +Unlike C, in Ruby,...
  72 +* Objects are strongly typed (and variable names themselves
  73 +have no type at all).
  74 +* There's no macros or preprocessor. No casts. No pointers
  75 +(nor pointer arithmetic). No typedefs, sizeof, nor enums.
  76 +* There are no header files. You just define your functions (usually
  77 +referred to as "methods") and classes in the main source code files.
  78 +* There's no <tt>#define</tt>. Just use constants instead.
  79 +* As of Ruby 1.8, code is interpreted at run-time rather than compiled to
  80 +any sort of machine- or byte-code.
  81 +* All variables live on the heap. Further, you don't need to free
  82 +them yourself -- the garbage collector takes care of that.
  83 +* Arguments to methods (i.e. functions) are passed by reference,
  84 +not by value.