diff --git a/_config.yml b/_config.yml index 53d7afa4e3..d989fab27a 100644 --- a/_config.yml +++ b/_config.yml @@ -239,6 +239,21 @@ locales: # url: /tr/security - text: Ruby Hakkında url: /tr/about + vi: + - text: Downloads + url: /vi/downloads + - text: Tài liệu + url: /vi/documentation + - text: Thư viện + url: /vi/libraries + - text: Cộng đồng + url: /vi/community + - text: Tin tức + url: /vi/news + - text: Bảo mật + url: /vi/security + - text: Về Ruby + url: /vi/about zh_cn: - text: 下载 url: /zh_cn/downloads @@ -299,6 +314,8 @@ locales: text: Procurar tr: text: Ara + vi: + text: Tìm zh_cn: text: 搜索 zh_tw: @@ -317,6 +334,7 @@ locales: pl: "Ruby - Najlepszy Przyjaciel Programisty" pt: "Ruby - O melhor amigo do programador" tr: "Ruby - A Programmer's Best Friend" + vi: "Ruby - Người bạn tri kỉ của lập trình viên" zh_cn: "Ruby - 程序员最要好的朋友" zh_tw: "Ruby - A Programmer's Best Friend" @@ -331,6 +349,7 @@ locales: pl: [Styczeń, Luty, Marzec, Kwiecień, Maj, Czerwiec, Lipiec, Sierpień, Wrzesień, Październik, Listopad, Grudzień] pt: [Janeiro, Fevereiro, Março, Abril, Maio, Junho, Julho, Agosto, Setembro, Outubro, Novembro, Dezembro] tr: [Ocak, Şubat, Mart, Nisan, Mayıs, Haziran, Temmuz, Ağustos, Eylül, Ekim, Kasım, Aralık] + vi: [Tháng một, Tháng hai, Tháng ba, Tháng tư, Tháng năm, Tháng sáu, Tháng bảy, Tháng tám, Tháng chín, Tháng mười, Tháng mười một, Tháng mười hai] posted_by: bg: "Публикувана от AUTHOR на %Y-%m-%d" @@ -345,6 +364,7 @@ locales: pl: "Zamieszczone przez AUTHOR %Y-%m-%d" pt: "Escrito por AUTHOR em %Y-%m-%d" tr: "AUTHOR tarafından %Y-%m-%d tarihinde gönderildi" + vi: "Đăng bởi AUTHOR vào %-d %b %Y" zh_cn: "由 AUTHOR 发表于 %Y-%m-%d" # zh_tw: @@ -362,6 +382,7 @@ locales: pt: "Traduzido por" tr: "Çeviri:" zh_cn: "翻译:" + vi: "Dịch bởi" # zh_tw: feed: @@ -413,6 +434,10 @@ locales: title: Ruby Son Haberler description: Ruby Son Haberler lang_code: tr + vi: + title: Tin tức Ruby + description: Những tin mới nhất từ ruby-lang.org. + lang_code: vi zh_cn: title: Ruby 新闻更新 description: 来自 ruby-lang.org 的最新文章。 @@ -567,6 +592,18 @@ locales: monthly_archives: Archives by Month yearly_archive_link: "%Y Archives" monthly_archive_link: "%B %Y" + vi: + other_news: Tin khác + more_news: Thêm Tin... + continue: Đọc tiếp... + back_to_year: "Trở về %Y Lưu trữ" + recent_news: Tin mới nhất + yearly_archive_title: "%Y " + monthly_archive_title: "%B %Y Lưu trữ" + yearly_archives: Lưu trữ bằng Năm + monthly_archives: Lưu trữ bằng Tháng + yearly_archive_link: "%Y Lưu trữ" + monthly_archive_link: "%B %Y" zh_cn: other_news: 其它新闻 more_news: 更多新闻... @@ -1361,6 +1398,69 @@ locales: recent_news: text: Son Haberler (RSS) url: /tr/feeds/news.rss + vi: + get_started: + text: Nhập môn, quá dễ! + try_ruby: + text: Thử Ruby! (trong trình duyệt) + <<: *try_ruby + quickstart: + text: Ruby trong 20 phút + url: /vi/documentation/quickstart/ + ruby_from_other_languages: + text: Ruby từ những ngôn ngữ khác + url: /vi/documentation/ruby-from-other-languages/ + explore: + text: Khám phá một thề giới mới… + documentation: + text: Tài liệu + url: /vi/documentation/ + books: + text: Sách + <<: *books + libraries: + text: Thư viện + url: /vi/libraries/ + success_stories: + text: Những câu chuyện thành công + url: /vi/documentation/success-stories/ + participate: + text: Tham gia vào một cộng đồng lớn mạnh và thân thiện. + mailing_lists: + text: Mailing Lists + url: /vi/community/mailing-lists/ + description: | + Trao đổi về Ruby với các lập trình viên trên thế giới + user_groups: + text: Nhóm người dùng + url: /vi/community/user-groups/ + description: | + Làm quen với những Rubyist trong khu vực của bạn. + weblogs: + text: Weblogs + url: /vi/community/weblogs/ + description: | + Đọc về những gì đang xảy ra với cộng đồng Ruby. + ruby_core: + text: Lõi Ruby + url: /vi/community/ruby-core/ + description: | + Giúp hoàn thiện Ruby. + issue_tracking: + text: Thông báo lỗi + url: https://bugs.ruby-lang.org/ + description: | + Báo hoặc giúp xử lý các lỗi trong Ruby. + top_ruby_projects: + text: Những dự án Ruby hàng đầu + more: + text: Nhiều hơn nữa… + url: /vi/libraries/top-projects/ + syndicate: + text: Syndicate + recent_news: + text: Tin mới (RSS) + url: /vi/feeds/news.rss zh_tw: get_started: text: 上手入門, 一點都不難! @@ -1597,6 +1697,15 @@ locales: # subscribe: Subscribe # unsubscribe: Unsubscribe # submit: Submit Form + vi: + list: Mailing List + first_name: Tên + last_name: Họ + email: Email + action: Hành động + subscribe: Đăng kí + unsubscribe: Hủy đăng kí + submit: Nộp đơn zh_cn: list: 邮件列表 first_name: 姓 @@ -1683,6 +1792,12 @@ locales: Ruby topluluğunun üyeleri tarafından gururla sürdürülmektedir. Herhangi bir soru ya da öneriniz için lütfen site yöneticimiz ile irtibata geçin. + vi: | + Website này được tạo ra với Ruby sử dụng Jekyll. + Trang được bảo trì bởi các thành viên của cộng đồng Ruby. + Xin đóng góp trên GitHub + hay liên lạc với webmaster (bằng tiếng Anh) + nếu có câu hỏi hoặc ý kiến phản hồi về trang này. zh_cn: | 本网站使用 Ruby 工具 Jekyll 制作,并有幸由来自 Ruby 社区的会员共同维护。 请贡献代码至 GitHub。 diff --git a/_includes/footer.html b/_includes/footer.html index 8fd6e170a1..d66f5b1568 100644 --- a/_includes/footer.html +++ b/_includes/footer.html @@ -5,6 +5,7 @@ English, Spanish, French, +Vietnamese, Bahasa Indonesia, Italian, Japanese, diff --git a/index.html b/index.html index 1b01e0d102..1d77f6e5b9 100644 --- a/index.html +++ b/index.html @@ -17,6 +17,7 @@ "pl": "pl", "pt": "pt", "tr": "tr", + "vi": "vi", "zh-CN": "zh_cn", "zh-TW": "zh_tw" }; diff --git a/vi/about/index.md b/vi/about/index.md new file mode 100644 index 0000000000..ac7c92e249 --- /dev/null +++ b/vi/about/index.md @@ -0,0 +1,211 @@ +--- +layout: page +title: "About Ruby" +lang: en +--- + +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? + +### The Ideals of Ruby’s Creator + +Ruby is a language of careful balance. Its creator, [Yukihiro “Matz” +Matsumoto][1], blended parts of his favorite languages (Perl, Smalltalk, +Eiffel, Ada, and Lisp) to form a new language that balanced functional +programming with imperative programming. + +He has often said that he is “trying to make Ruby natural, not simple,” +in a way that mirrors life. + +Building on this, he adds: + +> Ruby is simple in appearance, but is very complex inside, just like +> our human body[1](#fn1). + +### About Ruby’s Growth + +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. + +![Graph courtesy of +Gmane.](http://gmane.org/plot-rate.php?group=gmane.comp.lang.ruby.general&width=320&height=160&title=Ruby-Talk+Activity +"Graph courtesy of Gmane."){: style="padding-left:8px;"} +{: style="float:right"} + +Ruby-Talk, the primary [mailing list](/en/community/mailing-lists/) for +discussion of the Ruby language, climbed to an average of 200 messages +per day in 2006. It has dropped in recent years as the size of the +community pushed discussion from one central list into many smaller +groups. + +The [TIOBE index][6], 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](#fn2). + +Ruby is also [completely free]({{ site.license.url }}). Not only free of charge, but +also free to use, copy, modify, and distribute. + +### Seeing Everything as an Object + +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](#fn3).” + +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. + +{% highlight ruby %} +5.times { print "We *love* Ruby -- it's outrageous!" } +{% endhighlight %} + +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. + +### Ruby’s Flexibility + +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. + +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. + +{% highlight ruby %} +class Numeric + def plus(x) + self.+(x) + end +end + +y = 5.plus 6 +# y is now equal to 11 +{% endhighlight %} + +Ruby’s operators are syntactic sugar for methods. You can redefine them +as well. + +### Blocks, a Truly Expressive Feature + +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. + +Blocks are inspired by functional languages. Matz said, “in Ruby +closures, I wanted to respect the Lisp culture[4](#fn4).” + +{% highlight ruby %} +search_engines = + %w[Google Yahoo MSN].map do |engine| + "http://www." + engine.downcase + ".com" + end +{% endhighlight %} + +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. + +### Ruby and the Mixin + +Unlike many object-oriented languages, Ruby features single inheritance +only, **on purpose**. But Ruby knows the concept of modules (called +Categories in Objective-C). Modules are collections of methods. + +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. + +{% highlight ruby %} +class MyArray + include Enumerable +end +{% endhighlight %} + +Generally, Rubyists see this as a much clearer way than multiple +inheritance, which is complex and can be too restrictive. + +### Ruby’s Visual Appearance + +While Ruby often uses very limited punctuation and usually prefers +English keywords, some punctuation is used to decorate Ruby. Ruby needs +no variable declarations. It uses simple naming conventions to denote +the scope of variables. + +* `var` could be a local variable. +* `@var` is an instance variable. +* `$var` is a global variable. + +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. + +### Beyond the Basics + +Ruby has a wealth of other features, among which are the following: + +* Ruby has exception handling features, like Java or Python, to make it + easy to handle errors. +^ + +* Ruby features a true mark-and-sweep garbage collector for all Ruby + objects. No need to maintain reference counts in extension libraries. + As Matz says, “This is better for your health.” +^ + +* Writing C extensions in Ruby is easier than in Perl or Python, with a + very elegant API for calling Ruby from C. This includes calls for + embedding Ruby in software, for use as a scripting language. A SWIG + interface is also available. +^ + +* Ruby can load extension libraries dynamically if an OS allows. +^ + +* Ruby features OS independent threading. Thus, for all platforms on + which Ruby runs, you also have multithreading, regardless of if the OS + supports it or not, even on MS-DOS! +^ + +* Ruby is highly portable: it is developed mostly on GNU/Linux, but + works on many types of UNIX, Mac OS X, Windows 95/98/Me/NT/2000/XP, + DOS, BeOS, OS/2, etc. + +#### References + +1 Matz, speaking on the Ruby-Talk mailing list, [May 12th, +2000][2]. +{: #fn1} + +2 See the [Ruby on Rails][3] home page for more. +{: #fn2} + +3 Matz, in [An Interview with the Creator of Ruby][4], Nov. +29th, 2001. +{: #fn3} + +4 Matz, in [Blocks and Closures in Ruby][5], December 22nd, +2003. +{: #fn4} + + + +[1]: http://www.rubyist.net/~matz/ +[2]: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/2773 +[3]: http://rubyonrails.org/ +[4]: http://www.linuxdevcenter.com/pub/a/linux/2001/11/29/ruby.html +[5]: http://www.artima.com/intv/closures2.html +[6]: http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html diff --git a/vi/about/license.txt b/vi/about/license.txt new file mode 100644 index 0000000000..f7f597fb57 --- /dev/null +++ b/vi/about/license.txt @@ -0,0 +1,56 @@ +Ruby is copyrighted free software by Yukihiro Matsumoto . +You can redistribute it and/or modify it under either the terms of the +2-clause BSDL (see the file BSDL), or the conditions below: + + 1. You may make and give away verbatim copies of the source form of the + software without restriction, provided that you duplicate all of the + original copyright notices and associated disclaimers. + + 2. You may modify your copy of the software in any way, provided that + you do at least ONE of the following: + + a) place your modifications in the Public Domain or otherwise + make them Freely Available, such as by posting said + modifications to Usenet or an equivalent medium, or by allowing + the author to include your modifications in the software. + + b) use the modified software only within your corporation or + organization. + + c) give non-standard binaries non-standard names, with + instructions on where to get the original software distribution. + + d) make other distribution arrangements with the author. + + 3. You may distribute the software in object code or binary form, + provided that you do at least ONE of the following: + + a) distribute the binaries and library files of the software, + together with instructions (in the manual page or equivalent) + on where to get the original distribution. + + b) accompany the distribution with the machine-readable source of + the software. + + c) give non-standard binaries non-standard names, with + instructions on where to get the original software distribution. + + d) make other distribution arrangements with the author. + + 4. You may modify and include the part of the software into any other + software (possibly commercial). But some files in the distribution + are not written by the author, so that they are not under these terms. + + For the list of those files and their copying conditions, see the + file LEGAL. + + 5. The scripts and library files supplied as input to or produced as + output from the software do not automatically fall under the + copyright of the software, but belong to whomever generated them, + and may be sold commercially, and may be aggregated with this + software. + + 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE. \ No newline at end of file diff --git a/vi/community/conferences/index.md b/vi/community/conferences/index.md new file mode 100644 index 0000000000..f6ce56c284 --- /dev/null +++ b/vi/community/conferences/index.md @@ -0,0 +1,82 @@ +--- +layout: page +title: "Ruby Conferences" +lang: en +--- + +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. + +### Major Ruby Conferences + +[RubyConf][1] +: Every year since 2001, [Ruby Central, Inc.][2] 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 at, all the + RubyConfs but one. + +[RubyKaigi][3] +: 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. + +[EuRuKo (Europaeische Ruby Konferenz)][4] +: 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. + +[Open Source Developer Conference][5] +: 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. + +### Regional Ruby Conferences + +[Ruby Central][2] administers a [Regional Conference Grant Program][6], +to offset expenses for local and regional groups wanting to organize +events. + +Ruby Central has also teamed up with [SDForum][7] to produce the Silicon +Valley Ruby Conference, entering its second year in 2007. + +[RubyNation][8] is an annual Ruby conference serving the Virginia, West +Virginia, Maryland, and Washington, DC areas. + +WindyCityRails is an annual gathering for all who are passionate about +Ruby on Rails. The Chicago-based conference has served the Ruby +community since 2008. Visit [http://windycityrails.org][9] for details. + +### Ruby At Other Conferences + +There has been a Ruby track at the [O’Reilly Open Source Conference][10] +(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][11], including Ruby Central’s +[RailsConf][12], [RailsConf Europe][13] (co-produced in 2006 by Ruby +Central and [Skills Matter][14], and in 2007 by Ruby Central and +O’Reilly), and Canada on Rails. + + + +[1]: http://rubyconf.org/ +[2]: http://www.rubycentral.org +[3]: http://rubykaigi.org/ +[4]: http://euruko.org +[5]: http://www.osdc.com.au/ +[6]: http://www.rubycentral.org/rcg2006.pdf +[7]: http://www.sdforum.org +[8]: http://rubynation.org/ +[9]: http://windycityrails.org +[10]: http://conferences.oreillynet.com/os2006/ +[11]: http://www.rubyonrails.org +[12]: http://www.railsconf.org +[13]: http://europe.railsconf.org +[14]: http://www.skillsmatter.com diff --git a/vi/community/index.md b/vi/community/index.md new file mode 100644 index 0000000000..7264999d75 --- /dev/null +++ b/vi/community/index.md @@ -0,0 +1,62 @@ +--- +layout: page +title: "Community" +lang: en +--- + +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. + +If you are interested in getting involved, here are a couple of places +to start: + +[Ruby User Groups](user-groups/) +: 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. + +[Ruby Mailing Lists and Newsgroups](mailing-lists/) +: 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. + +[Ruby on IRC](irc://irc.freenode.net/ruby-lang) +: The Ruby Language IRC Channel is a wonderful way to chat with fellow + Rubyists. ([Previous Chat Logs][1]) + +[Ruby Core](ruby-core/) +: Now is a fantastic time to follow Ruby’s development. + If you are interested in helping with Ruby, start here. + +[Weblogs About Ruby](weblogs/) +: 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. + +[Ruby Conferences](conferences/) +: 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. + +[The Ruby Mentor Project][2] +: 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 from. This is intended to be a + little less intimidating than a mailing list, though Ruby Talk does + welcome questions from beginners. + +General Ruby Information +: * [Ruby Central][3] + * [Ruby at Open Directory Project][4] + * [Rails at Open Directory Project][5] + + + +[1]: http://meme.b9.com/ +[2]: http://rubymentor.rubyforge.org/ +[3]: http://www.rubycentral.org/ +[4]: http://dmoz.org/Computers/Programming/Languages/Ruby/ +[5]: http://dmoz.org/Computers/Programming/Languages/Ruby/Software/Rails/ diff --git a/vi/community/mailing-lists/index.md b/vi/community/mailing-lists/index.md new file mode 100644 index 0000000000..6bfb6f0cf3 --- /dev/null +++ b/vi/community/mailing-lists/index.md @@ -0,0 +1,44 @@ +--- +layout: page +title: "Mailing Lists" +lang: en +--- + +Mailing-lists are a great way to keep your finger on the pulse of the +Ruby community. Ruby has four primary English speaking mailing lists: + +Ruby-Talk +: This is the most popular mailing-list and deals with general topics + about Ruby. Ruby-Talk is mirrored by [Ruby-Forum.com][1]. ([FAQ][2] + and [Archives][3]) + +Ruby-Core +: This list deals with core and implementation topics about Ruby, often + used to run patches for review. ([Archives][4]) + +Ruby-Doc +: This list is for discussing documentation standards and tools for + Ruby. ([Archives at Gmane][5]) + +Ruby-CVS +: This list reports all commits to Ruby’s CVS repository. + +The comp.lang.ruby Newsgroup +: Those who prefer Usenet over mailing lists will want to checkout the + [comp.lang.ruby](news:comp.lang.ruby) newsgroup. + + +## Subscribe or Unsubscribe + +{% include subscription-form.html %} + +If you fail to receive a confirmation e-mail using the form, try +subscribing the [manual way](manual-instructions/). + + + +[1]: http://ruby-forum.com +[2]: http://rubyhacker.com/clrFAQ.html +[3]: http://blade.nagaokaut.ac.jp/ruby/ruby-talk/index.shtml +[4]: http://blade.nagaokaut.ac.jp/ruby/ruby-core/index.shtml +[5]: http://dir.gmane.org/gmane.comp.lang.ruby.documentation diff --git a/vi/community/mailing-lists/manual-instructions/index.md b/vi/community/mailing-lists/manual-instructions/index.md new file mode 100644 index 0000000000..2109775aa2 --- /dev/null +++ b/vi/community/mailing-lists/manual-instructions/index.md @@ -0,0 +1,65 @@ +--- +layout: page +title: "Manual Mailing List Instructions" +lang: en +--- + +To subscribe to a mailing list, please send a plain text mail +with the following mail body (not the subject) to the automated +“controller” address: + + subscribe Your-First-Name Your-Last-Name +{: .code} + +e.g. + + subscribe John Doe +{: .code} + +Ruby-Talk +: For the Ruby-Talk list, the controller address is + [ruby-talk-ctl@ruby-lang.org](mailto:ruby-talk-ctl@ruby-lang.org), the + posting address is + [ruby-talk@ruby-lang.org](mailto:ruby-talk@ruby-lang.org), and the + human administrator address is + [ruby-talk-admin@ruby-lang.org](mailto:ruby-talk-admin@ruby-lang.org). + +Ruby-Core +: For the Ruby-Core list, the controller address is + [ruby-core-ctl@ruby-lang.org](mailto:ruby-core-ctl@ruby-lang.org), the + posting address is + [ruby-core@ruby-lang.org](mailto:ruby-core@ruby-lang.org), and the + “human” administrator address is + [ruby-core-admin@ruby-lang.org](mailto:ruby-core-admin@ruby-lang.org). + +Ruby-Doc +: For the Ruby-Doc list, the controller address is + [ruby-doc-ctl@ruby-lang.org](mailto:ruby-doc-ctl@ruby-lang.org), the + posting address is + [ruby-doc@ruby-lang.org](mailto:ruby-doc@ruby-lang.org), and the + “human” administrator address is + [ruby-doc-admin@ruby-lang.org](mailto:ruby-doc-admin@ruby-lang.org). + +Ruby-CVS +: For the Ruby-CVS list, the controller address is + [ruby-cvs-ctl@ruby-lang.org](mailto:ruby-cvs-ctl@ruby-lang.org), the + posting address is + [ruby-cvs@ruby-lang.org](mailto:ruby-cvs@ruby-lang.org), and the + “human” administrator address is + [ruby-cvs-admin@ruby-lang.org](mailto:ruby-cvs-admin@ruby-lang.org). + +### Unsubscribing + +To unsubscribe from a list, send a mail which body is “unsubscribe” to +the **controller address**: + + unsubscribe +{: .code} + +Make sure to send a plain text mail, an HTML mail might not work. + +### Getting Help + +To see the list of commands, send a mail which body is “help” to the +controller address. + diff --git a/vi/community/ruby-core/index.md b/vi/community/ruby-core/index.md new file mode 100644 index 0000000000..69ac433505 --- /dev/null +++ b/vi/community/ruby-core/index.md @@ -0,0 +1,162 @@ +--- +layout: page +title: "Ruby Core" +lang: en +--- + +Now is a fantastic time to follow Ruby’s development. 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? + +The topics related to Ruby development covered here are: + +* [Using Subversion to Track Ruby Development](#following-ruby) +* [How to Use Git With the Main Ruby Repository](#git-ruby) +* [Improving Ruby, Patch by Patch](#patching-ruby) +* and, [Rules for Core Developers](#coding-standards) + +### Using Subversion to Track Ruby Development +{: #following-ruby} + +Getting the latest Ruby source code is a matter of an anonymous checkout +from the [Subversion][1] repository. From your command line: + +{% highlight sh %} +$ svn co http://svn.ruby-lang.org/repos/ruby/trunk ruby +{% endhighlight %} + +The `ruby` directory will now contain the latest source code +for the development version of Ruby (ruby-trunk). +Currently patches applied to the trunk are backported to the +stable 2.0.0 and 1.9.3 branches (see below). + +If you’d like to follow patching of Ruby 2.0.0, you should use the +`ruby_2_0_0` branch when checking out: + +{% highlight sh %} +$ svn co http://svn.ruby-lang.org/repos/ruby/branches/ruby_2_0_0 +{% endhighlight %} + +If you’d like to follow patching of Ruby 1.9.3, you should use the +`ruby_1_9_3` branch when checking out: + +{% highlight sh %} +$ svn co http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_3 +{% endhighlight %} + +This will check out the Ruby 1.9.3 development tree into a `ruby_1_9_3` +directory. Developers working on Ruby 1.9.3 are expected to migrate their +changes to Ruby’s trunk, so often the two branches are very similar, +with the exception of improvements made by Matz and Nobu to the language +itself. + +If you prefer, you may browse [Ruby’s Subversion repository via the web][2]. + +For information about Subversion, please see [the Subversion FAQ][3] and +[the Subversion book][4]. Alternatively, you may find [Pragmatic Version +Control with Subversion][5] to be a useful introductory book. + +### How to Use Git With the Main Ruby Repository +{: #git-ruby} + +Those who prefer to use [Git][6] over Subversion can find instructions +with [the mirror on GitHub][7], both for [those with commit access][8] +and [everybody else][9]. + +### Improving Ruby, Patch by Patch +{: #patching-ruby} + +The core team maintains an [issue tracker][10] 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/) 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. + +Please look over the [Patch Writer’s Guide][11] for some tips, straight +from Matz, on how to get your patches considered. + +To summarize, the steps for building a patch are: + +1. Check out a copy of the Ruby source code from Subversion. + Usually patches for bugfixes or new features should be submitted + for the trunk of Ruby’s source. Even if you wish to add a feature + to Ruby 1.9.3, it has to be proven in the trunk first. + + $ svn co http://svn.ruby-lang.org/repos/ruby/trunk ruby + + If you are fixing a bug that is specific to only one maintenance branch, + check out a copy of the respective branch, e.g. `ruby_1_9.3`. + + $ svn co http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_3 + +2. Add your improvements to the code. + +3. Create a patch. + + $ svn diff > ruby-changes.patch + +4. Create a ticket in the [issue tracker][10] or + email your patch to the [Ruby-Core mailing + list](/en/community/mailing-lists/) with a ChangeLog entry + describing the patch. + +5. If there are no issues raised about the patch, committers will be + given the approval to apply it. + +**Please note:** patches should be submitted as a [unified diff][12]. +For more on how patches are merged, see [the diffutils reference][13]. + +Discussion of Ruby’s development converges on the [Ruby-Core mailing +list](/en/community/mailing-lists/). 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. + +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. + +### Rules for Core Developers +{: #coding-standards} + +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: + +* All check-ins should be described in the `ChangeLog`, following the + [GNU conventions][14]. (Many Ruby core developers use Emacs `add-log` + mode, which can be accessed with the command `C-x 4 a`.) +* Check-in dates should be given in Japan Standard Time (UTC+9). +* 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. +* Function prototypes are used throughout Ruby’s source code and its + packaged extensions. +* Please, do not use C++-style comments (`//`), Ruby’s maintainers + instead prefer the standard C multi-line comment. (`/* .. */`) + +See also the information in [Ruby’s issue tracker][10]. + + + +[1]: http://subversion.apache.org/ +[2]: http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/ +[3]: http://subversion.apache.org/faq.html +[4]: http://svnbook.org +[5]: http://www.pragmaticprogrammer.com/titles/svn/ +[6]: http://git-scm.com/ +[7]: http://github.com/ruby/ruby +[8]: http://wiki.github.com/shyouhei/ruby/committerhowto +[9]: http://wiki.github.com/shyouhei/ruby/noncommitterhowto +[10]: https://bugs.ruby-lang.org/ +[11]: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/25139 +[12]: http://www.gnu.org/software/diffutils/manual/html_node/Unified-Format.html +[13]: http://www.gnu.org/software/diffutils/manual/html_node/Merging-with-patch.html#Merging%20with%20patch +[14]: http://www.gnu.org/prep/standards/standards.html#Change-Logs diff --git a/vi/community/user-groups/index.md b/vi/community/user-groups/index.md new file mode 100644 index 0000000000..3bb13481df --- /dev/null +++ b/vi/community/user-groups/index.md @@ -0,0 +1,43 @@ +--- +layout: page +title: "User Groups" +lang: en +--- + +In the programming community, user groups form support networks for +people interested in certain topics. They are a great place to increase +your skills and network with other programmers. User groups are informal +and their structure varies from group to group. Anyone can form their +own group and set their own rules and schedule. + +### Ruby User Groups + +If you want to get together with other Ruby programmers, a local user +group may be just the thing. Ruby user groups are entirely devoted to +Ruby. They typically feature monthly meetings, a mailing list, a website, +and if you're lucky, frequent hacking sessions (meetings devoted +to giving people a chance to write Ruby code). + +Information about Ruby user groups can be found on various websites: + +[rubyusersgroups.org][1] +: A public listing of Ruby groups throughout the world. Also allows + Rubyists to place themselves on a map of the world. + +[Ruby Meetup Groups][2] +: A substantial number of Ruby User Groups have chosen to make Meetup + their home. Meetup provides a number of tools for user groups, + including: private forums, a place for announcements, automated + meeting reminders, and a nice RSVP system. + +### Organizing Your Own Group + +If you are interested in forming your own group, be sure to find out if +there is already a Ruby user group in your area. Larger meetings are +usually much more fun, so starting your own group may not be the best +option if there is already one nearby. + + + +[1]: http://www.rubyusergroups.org/ +[2]: http://ruby.meetup.com diff --git a/vi/community/weblogs/index.md b/vi/community/weblogs/index.md new file mode 100644 index 0000000000..d00c0a57d8 --- /dev/null +++ b/vi/community/weblogs/index.md @@ -0,0 +1,70 @@ +--- +layout: page +title: "Weblogs" +lang: en +--- + +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. + +### Mining for Ruby Blogs + +[**Ruby on del.icio.us**][1]\: Ruby and Rails are consistently one of +the top fifty tags on del.icio.us, a popular link sharing site. Watch +the [ruby][1] tag for incoming obscure links and its [popularity +chart][2] for recent upcomers in the Ruby community. + +**Planets**\: some planets (online specialized feeds agregators) have been running for years now. A few of them providing convenient content: + +* [Ruby Corner][4] +* [Planet Ruby][5] +* [PlanetRubyOnRails.org][6] +* [PlanetRubyOnRails.com][7] + +### Blogs of Note + +A few notable blogs stand out for the frequency and immediacy of their +updates. + +* [**O’Reilly Ruby**][8] is a group blog with pertinent Ruby tutorials + and interviews with interesting folks from around the community. +* [**Riding Rails**][9] 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. +* [**Ruby Inside**][10] announces interesting applications and libraries + from throughout the world, both Ruby and Rails. +* [**Matz’ Blog**][11] 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! + +### Spreading the Word + +If you’ve got a Ruby blog you’ve started, it’s wise to link the blog on +[del.icio.us][12] 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.) + +Ruby is also a common topic on [Digg][13], [Slashdot][14], [reddit][15], +and [Hacker News][16], in their respective programming news. If you find +some brilliant code out there, be sure to let them know! + + + +[1]: http://del.icio.us/tag/ruby +[2]: http://del.icio.us/popular/ruby +[3]: http://technorati.com/search/ruby +[4]: http://rubycorner.com +[5]: http://planetruby.0x42.net/ +[6]: http://www.planetrubyonrails.org/ +[7]: http://www.planetrubyonrails.com/ +[8]: http://oreillynet.com/ruby/ +[9]: http://weblog.rubyonrails.org/ +[10]: http://www.rubyinside.com/ +[11]: http://www.rubyist.net/~matz/ +[12]: http://del.icio.us +[13]: http://digg.com/programming +[14]: http://developers.slashdot.org/ +[15]: http://www.reddit.com/r/ruby +[16]: http://news.ycombinator.com/ diff --git a/vi/documentation/index.md b/vi/documentation/index.md new file mode 100644 index 0000000000..ad2885d92a --- /dev/null +++ b/vi/documentation/index.md @@ -0,0 +1,169 @@ +--- +layout: page +title: "Documentation" +lang: en +--- + +Here you will find pointers to manuals, tutorials and references that +will come in handy when you feel like coding in Ruby. + +### Getting Started + +[Try Ruby!][1] +: An interactive tutorial that lets you try out Ruby right in your + browser. This 15-minute tutorial is aimed at beginners who want to get + a feeling of the language. + +[Ruby Koans][2] +: The Koans walk you along the path to enlightenment in order to learn + Ruby. The goal is to learn the Ruby language, syntax, structure, and + some common functions and libraries. We also teach you culture. + +[RubyMonk][3] +: Discover Ruby idioms, learn lessons and solve problems, all in your + browser! + +[Hackety Hack][4] +: The little coder’s starter kit. + A fun and easy way to learn about programming (through Ruby) using the + Shoes GUI Toolkit. + +[Why’s (Poignant) Guide to Ruby][5] +: An unconventional but interesting book that will teach you Ruby + through stories, wit, and comics. Originally created by *why the lucky + stiff*, this guide remains a classic for Ruby learners. + +[Ruby in Twenty Minutes](/en/documentation/quickstart/) +: A nice tutorial covering the basics of Ruby. From start to finish it + shouldn’t take you more than twenty minutes. + +[Ruby from Other Languages](/en/documentation/ruby-from-other-languages/) +: Coming to Ruby from another language? Whether it’s C, C++, Java, Perl, + PHP, or Python, this article has you covered! + +[Learning Ruby][6] +: A thorough collection of Ruby study notes for those who are new to the + language and in search of a solid introduction to Ruby’s concepts and + constructs. + +[Ruby Essentials][7] +: Ruby Essentials is a free on-line book designed to provide a concise + and easy to follow guide to learning Ruby. + +[Learn to Program][8] +: A wonderful little tutorial by Chris Pine for programming newbies. If + you don’t know how to program, start here. + +### Manuals + +[Programming Ruby][9] +: The seminal work on Ruby in English, this first edition of the + [Pragmatic Programmers’ book][10] is available for free online. + +[Ruby User’s Guide][11] +: Translated from the original Japanese version written by Yukihiro + Matsumoto (the creator of Ruby), this version, by Goto Kentaro and + Mark Slagell is nice overview of many aspects of the Ruby language. + +[The Ruby Programming Wikibook][12] +: A free online manual with beginner and intermediate content plus a + thorough language reference. + +### Reference Documentation + +[Ruby Core Reference][13] +: Pulled straight from the source code using [RDoc][14], this reference + work documents all of the core classes and modules (like String, + Array, Symbol, etc…). + +[Ruby Standard Library Reference][15] +: Also pulled from the source code using RDoc, this reference work + documents the standard library. + +[RubyDoc.info][16] +: The one-stop web site for reference documentation about Ruby gems and + GitHub-hosted Ruby projects. + +[Rails Searchable API Doc][17] +: Rails and Ruby documentation with smart searching. + +[APIdock][18] +: Ruby, Rails and RSpec documentation with users’ notes. + +### Editors and IDEs + +For coding in Ruby you can use the default editor of your operating +system. By the way, to be more effective in coding, it is worth to +choose a source code editor with basic Ruby support (e.g. +syntax-highlighting, file browsing) or an integrated development +environment with advanced features (e.g. code completion, refactoring, +testing support). + +Here is a list of popular tools used by Rubyists: + +* Linux and cross-platform tools: + * [Aptana Studio][19] + * [Emacs][20] with [Ruby mode][21] and [Rsense][22] + * [Geany][23] + * [gedit][24] + * [Vim][25] with [vim-ruby][26] plugin and [Rsense][22] + * [RubyMine][27] + * [SciTe][28] + * [NetBeans][36] + * [Sublime Text][37] + +* On Windows: + * [Notepad++][29] + * [E-TextEditor][30] + * [Ruby In Steel][31] + +* On Mac OS X: + * [TextMate][32] + * [TextWrangler][33] + +### Further Reading + +[Ruby-Doc.org][34] maintains a comprehensive list of English +documentation sources. There are also plenty of [books about Ruby][35]. +If you have questions about Ruby the [mailing +list](/en/community/mailing-lists/) is a great place to start. + + + +[1]: http://tryruby.org/ +[2]: http://rubykoans.com/ +[3]: http://rubymonk.com/ +[4]: http://hackety-hack.com/ +[5]: http://mislav.uniqpath.com/poignant-guide/ +[6]: http://rubylearning.com/ +[7]: http://www.techotopia.com/index.php/Ruby_Essentials +[8]: http://pine.fm/LearnToProgram/ +[9]: http://www.ruby-doc.org/docs/ProgrammingRuby/ +[10]: http://pragmaticprogrammer.com/titles/ruby/index.html +[11]: http://www.rubyist.net/~slagell/ruby/ +[12]: http://en.wikibooks.org/wiki/Ruby_programming_language +[13]: http://www.ruby-doc.org/core +[14]: http://rdoc.sourceforge.net +[15]: http://www.ruby-doc.org/stdlib +[16]: http://www.rubydoc.info/ +[17]: http://railsapi.com/ +[18]: http://apidock.com/ +[19]: http://www.aptana.com/ +[20]: http://www.gnu.org/software/emacs/ +[21]: http://www.emacswiki.org/emacs/RubyMode +[22]: http://cx4a.org/software/rsense/ +[23]: http://www.geany.org/ +[24]: http://projects.gnome.org/gedit/screenshots.html +[25]: http://www.vim.org/ +[26]: https://github.com/vim-ruby/vim-ruby +[27]: http://www.jetbrains.com/ruby/ +[28]: http://www.scintilla.org/SciTE.html +[29]: http://notepad-plus-plus.org/ +[30]: http://www.e-texteditor.com/ +[31]: http://www.sapphiresteel.com/ +[32]: http://macromates.com/ +[33]: http://www.barebones.com/products/textwrangler/ +[34]: http://ruby-doc.org +[35]: http://www.ruby-doc.org/bookstore +[36]: https://netbeans.org/ +[37]: http://www.sublimetext.com/ diff --git a/vi/documentation/quickstart/2/index.md b/vi/documentation/quickstart/2/index.md new file mode 100644 index 0000000000..a71debd1ce --- /dev/null +++ b/vi/documentation/quickstart/2/index.md @@ -0,0 +1,125 @@ +--- +layout: page +title: "Ruby in Twenty Minutes" +lang: en + +header: | +
+ 1 + | + 2 + | + 3 + | + 4 +
+

Ruby in Twenty Minutes

+ +--- + +What if we want to say “Hello” a lot without getting our fingers all +tired? We need to define a method! + +{% highlight ruby %} +irb(main):010:0> def h +irb(main):011:1> puts "Hello World!" +irb(main):012:1> end +=> nil +{% endhighlight %} + +The code `def h` starts the definition of the method. It tells Ruby that +we’re defining a method, that its name is `h`. The next line is the body +of the method, the same line we saw earlier: `puts "Hello World"`. +Finally, the last line `end` tells Ruby we’re done defining the method. +Ruby’s response `=> nil` tells us that it knows we’re done defining the +method. + +## The Brief, Repetitive Lives of a Method + +Now let’s try running that method a few times: + +{% highlight ruby %} +irb(main):013:0> h +Hello World! +=> nil +irb(main):014:0> h() +Hello World! +=> nil +{% endhighlight %} + +Well, that was easy. Calling a method in Ruby is as easy as just +mentioning its name to Ruby. If the method doesn’t take parameters +that’s all you need. You can add empty parentheses if you’d like, but +they’re not needed. + +What if we want to say hello to one person, and not the whole world? +Just redefine `h` to take a name as a parameter. + +{% highlight ruby %} +irb(main):015:0> def h(name) +irb(main):016:1> puts "Hello #{name}!" +irb(main):017:1> end +=> nil +irb(main):018:0> h("Matz") +Hello Matz! +=> nil +{% endhighlight %} + +So it works… but let’s take a second to see what’s going on here. + +## Holding Spots in a String + +What’s the `#{name}` bit? That’s Ruby’s way of inserting something into +a string. The bit between the braces is turned into a string (if it +isn’t one already) and then substituted into the outer string at that +point. You can also use this to make sure that someone’s name is +properly capitalized: + +{% highlight ruby %} +irb(main):019:0> def h(name = "World") +irb(main):020:1> puts "Hello #{name.capitalize}!" +irb(main):021:1> end +=> nil +irb(main):022:0> h "chris" +Hello Chris! +=> nil +irb(main):023:0> h +Hello World! +=> nil +{% endhighlight %} + +A couple of other tricks to spot here. One is that we’re calling the +method without parentheses again. If it’s obvious what you’re doing, the +parentheses are optional. The other trick is the default parameter +`World`. What this is saying is “If the name isn’t supplied, use the +default name of `"World"`”. + +## Evolving Into a Greeter + +What if we want a real greeter around, one that remembers your name and +welcomes you and treats you always with respect. You might want to use +an object for that. Let’s create a “Greeter” class. + +{% highlight ruby %} +irb(main):024:0> class Greeter +irb(main):025:1> def initialize(name = "World") +irb(main):026:2> @name = name +irb(main):027:2> end +irb(main):028:1> def say_hi +irb(main):029:2> puts "Hi #{@name}!" +irb(main):030:2> end +irb(main):031:1> def say_bye +irb(main):032:2> puts "Bye #{@name}, come back soon." +irb(main):033:2> end +irb(main):034:1> end +=> nil +{% endhighlight %} + +The new keyword here is `class`. This defines a new class called Greeter +and a bunch of methods for that class. Also notice `@name`. This is an +instance variable, and is available to all the methods of the class. As +you can see it’s used by `say_hi` and `say_bye`. + +So how do we get this Greeter class set in motion? [Create an +object.](../3/) + diff --git a/vi/documentation/quickstart/3/index.md b/vi/documentation/quickstart/3/index.md new file mode 100644 index 0000000000..0b84627af9 --- /dev/null +++ b/vi/documentation/quickstart/3/index.md @@ -0,0 +1,231 @@ +--- +layout: page +title: "Ruby in Twenty Minutes" +lang: en + +header: | +
+ 1 + | + 2 + | + 3 + | + 4 +
+

Ruby in Twenty Minutes

+ +--- + +Now let’s create a greeter object and use it: + +{% highlight ruby %} +irb(main):035:0> g = Greeter.new("Pat") +=> # +irb(main):036:0> g.say_hi +Hi Pat! +=> nil +irb(main):037:0> g.say_bye +Bye Pat, come back soon. +=> nil +{% endhighlight %} + +Once the `g` object is created, it remembers that the name is Pat. Hmm, +what if we want to get at the name directly? + +{% highlight ruby %} +irb(main):038:0> g.@name +SyntaxError: compile error +(irb):52: syntax error + from (irb):52 +{% endhighlight %} + +Nope, can’t do it. + +## Under the Object’s Skin + +Instance variables are hidden away inside the object. They’re not +terribly hidden, you see them whenever you inspect the object, and there +are other ways of accessing them, but Ruby uses the good object-oriented +approach of keeping data sort-of hidden away. + +So what methods do exist for Greeter objects? + +{% highlight ruby %} +irb(main):039:0> Greeter.instance_methods +=> ["method", "send", "object_id", "singleton_methods", + "__send__", "equal?", "taint", "frozen?", + "instance_variable_get", "kind_of?", "to_a", + "instance_eval", "type", "protected_methods", "extend", + "eql?", "display", "instance_variable_set", "hash", + "is_a?", "to_s", "class", "tainted?", "private_methods", + "untaint", "say_hi", "id", "inspect", "==", "===", + "clone", "public_methods", "respond_to?", "freeze", + "say_bye", "__id__", "=~", "methods", "nil?", "dup", + "instance_variables", "instance_of?"] +{% endhighlight %} + +Whoa. That’s a lot of methods. We only defined two methods. What’s going +on here? Well this is **all** of the methods for Greeter objects, a +complete list, including ones defined by ancestor classes. If we want to +just list methods defined for Greeter we can tell it to not include +ancestors by passing it the parameter `false`, meaning we don’t want +methods defined by ancestors. + +{% highlight ruby %} +irb(main):040:0> Greeter.instance_methods(false) +=> ["say_bye", "say_hi"] +{% endhighlight %} + +Ah, that’s more like it. So let’s see which methods our greeter object +responds to: + +{% highlight ruby %} +irb(main):041:0> g.respond_to?("name") +=> false +irb(main):042:0> g.respond_to?("say_hi") +=> true +irb(main):043:0> g.respond_to?("to_s") +=> true +{% endhighlight %} + +So, it knows `say_hi`, and `to_s` (meaning convert something to a +string, a method that’s defined by default for every object), but it +doesn’t know `name`. + +## Altering Classes—It’s Never Too Late + +But what if you want to be able to view or change the name? Ruby +provides an easy way of providing access to an object’s variables. + +{% highlight ruby %} +irb(main):044:0> class Greeter +irb(main):045:1> attr_accessor :name +irb(main):046:1> end +=> nil +{% endhighlight %} + +In Ruby, you can open a class up again and modify it. The changes will +be present in any new objects you create and even available in existing +objects of that class. So, let’s create a new object and play with its +`@name` property. + +{% highlight ruby %} +irb(main):047:0> g = Greeter.new("Andy") +=> # +irb(main):048:0> g.respond_to?("name") +=> true +irb(main):049:0> g.respond_to?("name=") +=> true +irb(main):050:0> g.say_hi +Hi Andy! +=> nil +irb(main):051:0> g.name="Betty" +=> "Betty" +irb(main):052:0> g +=> # +irb(main):053:0> g.name +=> "Betty" +irb(main):054:0> g.say_hi +Hi Betty! +=> nil +{% endhighlight %} + +Using `attr_accessor` defined two new methods for us, `name` to get the +value, and `name=` to set it. + +## Greeting Anything and Everything, MegaGreeter Neglects None! + +This greeter isn’t all that interesting though, it can only deal with +one person at a time. What if we had some kind of MegaGreeter that could +either greet the world, one person, or a whole list of people? + +Let’s write this one in a file instead of directly in the interactive +Ruby interpreter IRB. + +To quit IRB, type “quit”, “exit” or just hit Control-D. + +{% highlight ruby %} +#!/usr/bin/env ruby + +class MegaGreeter + attr_accessor :names + + # Create the object + def initialize(names = "World") + @names = names + end + + # Say hi to everybody + def say_hi + if @names.nil? + puts "..." + elsif @names.respond_to?("each") + # @names is a list of some kind, iterate! + @names.each do |name| + puts "Hello #{name}!" + end + else + puts "Hello #{@names}!" + end + end + + # Say bye to everybody + def say_bye + if @names.nil? + puts "..." + elsif @names.respond_to?("join") + # Join the list elements with commas + puts "Goodbye #{@names.join(", ")}. Come back soon!" + else + puts "Goodbye #{@names}. Come back soon!" + end + end + +end + + +if __FILE__ == $0 + mg = MegaGreeter.new + mg.say_hi + mg.say_bye + + # Change name to be "Zeke" + mg.names = "Zeke" + mg.say_hi + mg.say_bye + + # Change the name to an array of names + mg.names = ["Albert", "Brenda", "Charles", + "Dave", "Engelbert"] + mg.say_hi + mg.say_bye + + # Change to nil + mg.names = nil + mg.say_hi + mg.say_bye +end +{% endhighlight %} + +Save this file as “ri20min.rb”, and run it as “ruby ri20min.rb”. The +output should be: + + Hello World! + Goodbye World. Come back soon! + Hello Zeke! + Goodbye Zeke. Come back soon! + Hello Albert! + Hello Brenda! + Hello Charles! + Hello Dave! + Hello Engelbert! + Goodbye Albert, Brenda, Charles, Dave, Engelbert. Come + back soon! + ... + ... +{: .code} + +There are a lot of new things thrown into this final example that we +[can take a deeper look at.](../4/) + diff --git a/vi/documentation/quickstart/4/index.md b/vi/documentation/quickstart/4/index.md new file mode 100644 index 0000000000..7ad3f66402 --- /dev/null +++ b/vi/documentation/quickstart/4/index.md @@ -0,0 +1,156 @@ +--- +layout: page +title: "Ruby in Twenty Minutes" +lang: en + +header: | +
+ 1 + | + 2 + | + 3 + | + 4 +
+

Ruby in Twenty Minutes

+ +--- + +So, looking deeper at our new program, notice the initial lines, which +begin with a hash mark (#). In Ruby, anything on a line after a hash +mark is a comment and is ignored by the interpreter. The first line of +the file is a special case, and under a Unix-like operating system tells +the shell how to run the file. The rest of the comments are there just +for clarity. + +Our `say_hi` method has become a bit trickier: + +{% highlight ruby %} +# Say hi to everybody +def say_hi + if @names.nil? + puts "..." + elsif @names.respond_to?("each") + # @names is a list of some kind, iterate! + @names.each do |name| + puts "Hello #{name}!" + end + else + puts "Hello #{@names}!" + end +end +{% endhighlight %} + +It now looks at the `@names` instance variable to make decisions. If +it’s nil, it just prints out three dots. No point greeting nobody, +right? + +## Cycling and Looping—a.k.a. Iteration + +If the `@names` object responds to `each`, it is something that you can +iterate over, so iterate over it and greet each person in turn. Finally, +if `@names` is anything else, just let it get turned into a string +automatically and do the default greeting. + +Let’s look at that iterator in more depth: + +{% highlight ruby %} +@names.each do |name| + puts "Hello #{name}!" +end +{% endhighlight %} + +`each` is a method that accepts a block of code then runs that block of +code for every element in a list, and the bit between `do` and `end` is +just such a block. A block is like an anonymous function or `lambda`. +The variable between pipe characters is the parameter for this block. + +What happens here is that for every entry in a list, `name` is bound to +that list element, and then the expression `puts "Hello #{name}!"` is +run with that name. + +Most other programming languages handle going over a list using the +`for` loop, which in C looks something like: + +{% highlight c %} +for (i=0; i