国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

directory search
Ruby用戶指南 3、開(kāi)始 4、簡(jiǎn)單的例子 5、字符串 6、正則表達(dá)式 7、數(shù)組 8、回到那些簡(jiǎn)單的例子 9、流程控制 10、迭代器 11、面向?qū)ο笏季S 12、方法 13、類(lèi) 14、繼承 15、重載方法 16、訪問(wèn)控制 17、單態(tài)方法 18、模塊 19、過(guò)程對(duì)象 20、變量 21、全局變量 22、實(shí)變量 23、局部變量 24、類(lèi)常量 25、異常處理:rescue 26、異常處理:ensure 27、存取器 28、對(duì)象的初始化 29、雜項(xiàng) RGSS入門(mén)教程 1、什么是RGSS 2、開(kāi)始:最簡(jiǎn)單的腳本 3、數(shù)據(jù)類(lèi)型:數(shù)字 4、數(shù)據(jù)類(lèi)型:常量與變量 5、數(shù)據(jù)類(lèi)型:字符串 6、控制語(yǔ)句:條件分歧語(yǔ)句 7、控制語(yǔ)句:循環(huán) 8、函數(shù) 9、對(duì)象與類(lèi) 10、顯示圖片 11、數(shù)組 12、哈希表(關(guān)聯(lián)數(shù)組) 13、類(lèi) 14、數(shù)據(jù)庫(kù) 15、游戲?qū)ο?/a> 16、精靈的管理 17、窗口的管理 18、活動(dòng)指令 19、場(chǎng)景類(lèi) Programming Ruby的翻譯 Programming Ruby: The Pragmatic Programmer's Guide 前言 Roadmap Ruby.new 類(lèi),對(duì)象和變量 容器Containers,塊Blocks和迭代Iterators 標(biāo)準(zhǔn)類(lèi)型 深入方法 表達(dá)式Expressions 異常,捕捉和拋出(已經(jīng)開(kāi)始,by jellen) 模塊 基本輸入輸出 線程和進(jìn)程 當(dāng)遭遇挫折 Ruby和它的世界 Ruby和Web開(kāi)發(fā) Ruby Tk Ruby 和微軟的 Windows 擴(kuò)展Ruby Ruby語(yǔ)言 (by jellen) 類(lèi)和對(duì)象 (by jellen) Ruby安全 反射Reflection 內(nèi)建類(lèi)和方法 標(biāo)準(zhǔn)庫(kù) OO設(shè)計(jì) 網(wǎng)絡(luò)和Web庫(kù) Windows支持 內(nèi)嵌文檔 交互式Ruby Shell 支持 Ruby參考手冊(cè) Ruby首頁(yè) 卷首語(yǔ) Ruby的啟動(dòng) 環(huán)境變量 對(duì)象 類(lèi) 執(zhí)行 結(jié)束時(shí)的相關(guān)處理 線程 安全模型 正則表達(dá)式 字句構(gòu)造 程序 變量和常數(shù) 字面值 操作符表達(dá)式 控制結(jié)構(gòu) 方法調(diào)用 類(lèi)/方法的定義 內(nèi)部函數(shù) 內(nèi)部變量 內(nèi)部常數(shù) 內(nèi)部類(lèi)/模塊/異常類(lèi) 附加庫(kù) Ruby變更記錄 ruby 1.6 特性 ruby 1.7 特性 Ruby術(shù)語(yǔ)集 Ruby的運(yùn)行平臺(tái) pack模板字符串 sprintf格式 Marshal格式 Ruby FAQ Ruby的陷阱
characters



本書(shū)是Ruby程序設(shè)計(jì)語(yǔ)言的參考手冊(cè)。用Ruby,在寫(xiě)好程序的基礎(chǔ)上,你還能提高生產(chǎn)效率,并享受編程過(guò)程。

這雖然是一種大膽的觀點(diǎn),但是我相信您會(huì)在讀完本書(shū)之后會(huì)同意他們的觀點(diǎn)。這是我們的親身經(jīng)歷。

作為注重實(shí)效的程序員,我們嘗試了很多種語(yǔ)言,我們用這些工具簡(jiǎn)化我們的工作,工具確實(shí)也能讓我們更好的工作??墒谴饲拔覀冇眠^(guò)的語(yǔ)言一直讓我們失望。

我們的工作目的就是解決問(wèn)題,而不是做編譯器,所以我們喜歡動(dòng)態(tài)語(yǔ)言,它適應(yīng)我們,沒(méi)有獨(dú)斷性(arbitrary),有嚴(yán)格的規(guī)則。我們能用代碼順暢的溝通,能用代碼正確有效的表達(dá)需求。而且,我們寫(xiě)的代碼越少,出錯(cuò)的機(jī)會(huì)也越少(這樣也會(huì)減少我們的手腕和手指的工作量)。

我們要求盡可能的提高生產(chǎn)效率,所以我們希望寫(xiě)完代碼之后馬上能運(yùn)行起來(lái);我們必須從開(kāi)發(fā)時(shí)間中留出時(shí)間用于調(diào)試。他也能幫助我們?cè)诰帉?xiě)時(shí)提煉代碼;如果你必須花費(fèi)兩個(gè)小時(shí)寫(xiě)一個(gè)循環(huán),那你可能也要用punch cards和成批編輯提交你的工作。(We want to be as productive as possible, so we want our code to run the first time; time spent in the debugger is time stolen from the development clock. It also helps if we can try out code as we edit it; if you have to wait for a 2-hour make cycle, you may as well be using punch cards and submitting your work for batch compilation. )

我們需要一個(gè)具有很高抽象層的語(yǔ)言,語(yǔ)言的抽象層越高,我們把需求轉(zhuǎn)化為代碼所需的時(shí)間越少。

當(dāng)我們發(fā)現(xiàn)了Ruby,我們認(rèn)識(shí)到我們找到了我們?cè)谝恢睂ふ业臇|西。和我們用過(guò)的其他語(yǔ)言相比,ruby顯得【stays out of your way】,你可以集中精力處理手邊的事情,而不必去過(guò)多的陷在編譯器和語(yǔ)言問(wèn)題中。ruby正是如此讓你能成為一個(gè)更好的程序員:你只需專心地為用戶解決問(wèn)題,而不是和編譯器糾纏。

Ruby的閃光點(diǎn)

采用真正的面向?qū)ο笳Z(yǔ)言,比如Smalltalk,摒棄除去那些未成熟新奇的語(yǔ)法,創(chuàng)造更多的有用的,忠實(shí)于文檔的代碼。這樣Ruby也加入到這些適應(yīng)性強(qiáng)且又實(shí)用的工具(比如:Python and Perl)之中。你或許要終身使用Ruby作為你的工具了。(Take a true object-oriented language, such as Smalltalk. Drop the unfamiliar syntax and move to more conventional, file-based source code. Now add in a good measure of the flexibility and convenience of languages such asPython and Perl . You end up with Ruby. )

OO愛(ài)好者有很多原因喜歡Ruby:純面向?qū)ο螅ㄈ魏螙|西都是對(duì)象),元類(lèi),閉包,迭代,無(wú)處不在的集合。Smalltalk用戶會(huì)感到很熟悉(c++和java用戶可能會(huì)嫉妒了)。
同時(shí),perl和python的擁護(hù)者也有他們很多喜歡perl或者python的特點(diǎn):完全的正則表達(dá)式的支持,與底層操作系統(tǒng)的緊密結(jié)合,便利的捷徑,以及動(dòng)態(tài)調(diào)用。

Ruby很容易去學(xué)習(xí),每天的任務(wù)是簡(jiǎn)單的編寫(xiě)代碼,完成之后,這些代碼很容易維護(hù)和完善。不過(guò)畢竟,很多困難的事情最初或許并不被認(rèn)為很困難。但是Ruby遵循的是Principle of Least Surprise原理,即:事情會(huì)按你的預(yù)想發(fā)展,并且?guī)缀鯖](méi)有特例或者例外。當(dāng)然,就是這點(diǎn)讓你在編程時(shí)感覺(jué)到不同。( is easy to learn. Everyday tasks are simple to code, and once you've done them, they are easy to maintain and grow. Apparently difficult things often turn out not to have been difficult after all. Ruby follows the Principle of Least Surprise---things work the way you would expect them to, with very few special cases or exceptions. And that really does make a difference when you're programming. )

我們稱 Ruby為透明語(yǔ)言。這就是說(shuō), Ruby不會(huì)讓你寫(xiě)下的解決方案因眾多的語(yǔ)法而模糊不清,

We call Ruby a transparent language. By that we mean that Ruby doesn't obscure the solutions you write behind lots of syntax and the need to churn out reams of support code just to get simple things done. With Ruby you write programs close to the problem domain. Rather than constantly mapping your ideas and designs down to the pedestrian level of most languages, with Ruby you'll find you can express them directly and express them elegantly. This means you code faster. It also means your programs stay readable and maintainable.

使用Ruby,我們可能會(huì)經(jīng)常為它的特點(diǎn)感到驚奇,沒(méi)有那么多得語(yǔ)法錯(cuò)誤,沒(méi)有類(lèi)型錯(cuò)誤,更少的bug。這很有用,它會(huì)讓我們更少出錯(cuò),沒(méi)有在每行結(jié)尾機(jī)械式的加入分號(hào),省得類(lèi)型定義的麻煩(特別是分散在多個(gè)文件中的時(shí)候)。沒(méi)有不需要的語(yǔ)句會(huì)讓編譯器報(bào)錯(cuò)。

那么,為什么要學(xué)習(xí)ruby呢?因?yàn)槲覀冋J(rèn)為它能幫助我們更好的編程,它將幫助你把主要注意力集中在實(shí)質(zhì)的東西上,而不必過(guò)分分心??傊?,它將使你生活變得容易。

Ruby是一種什么樣的語(yǔ)言?

In the old days, the distinction between languages was simple: they were either compiled, like C or Fortran, or interpreted, like BASIC. Compiled languages gave you speed and low-level access; interpreted languages were higher-level but slower.

Times change, and things aren't that simple anymore. Some language designers have taken to calling their creations ``scripting languages.'' By this, we guess they mean that their languages are interpreted and can be used to replace batch files and shell scripts, orchestrating the behavior of other programs and the underlying operating system. Perl, TCL, and Python have all been called scripting languages.

What exactly is a scripting language? Frankly we don't know if it's a distinction worth making. In Ruby, you can access all the underlying operating system features. You can do the same stuff in Ruby that you can in Perl or Python, and you can do it more cleanly. But Ruby is fundamentally different. It is a true programming language, too, with strong theoretical roots and an elegant, lightweight syntax. You could hack together a mess of ``scripts'' with Ruby, but you probably won't. Instead, you'll be more inclined to engineer a solution, to produce a program that is easy to understand, simple to maintain, and a piece of cake to extend and reuse in the future.

Although we have used Ruby for scripting jobs, most of the time we use it as a general-purpose programming language. We've used it to write GUI applications and middle-tier server processes, and we're using it to format large parts of this book. Others have used it for managing server machines and databases. Ruby is serving Web pages, interfacing to databases and generating dynamic content. People are writing artificial intelligence and machine learning programs in Ruby, and at least one person is using it to investigate natural evolution. Ruby's finding a home as a vehicle for exploratory mathematics. And people all over the world are using it as a way of gluing together all their different applications. It truly is a great language for producing solutions in a wide variety of problem domains.

Ruby適合我嗎?

Ruby is not the universal panacea for programmers' problems. There will always be times when you'll need a particular language: the environment may dictate it, you may have special libraries you need, performance concerns, or simply an issue with training. We haven't given up languages such as Java and C++ entirely (although there are times when we wish we could).

However, Ruby is probably more applicable than you might think. It is easy to extend, both from within the language and by linking in third-party libraries. It is portable across a number of platforms. It's relatively lightweight and consumes only modest system resources. And it's easy to learn; we've known people who've put Ruby code into production systems within a day of picking up drafts of this book. We've used Ruby to implement parts of an X11 window manager, a task that's normally considered severe C coding. Ruby excelled, and helped us write code in hours that would otherwise have taken days.

Once you get comfortable with Ruby, we think you'll keep coming back to it as your language of choice.

為什么我們要寫(xiě)這本書(shū)?

So we'd just finished writing The Pragmatic Programmer, our families had just started talking to us again, and suddenly we felt the need to write another book. Why? We guess it comes down to a kind of missionary zeal.

Ruby was created by Yukihiro Matsumoto (Matz) in Japan. Since 1995, its popularity in Japan has grown at an astounding rate; there are rumors that Ruby is more popular than Python in Japan. But to date, much of the detailed Ruby documentation is in Japanese. It probably isn't a programming language you'd just stumble across.

We wanted to spread the word, to have more people outside Japan using Ruby and enjoying the benefits, so we decided to document Ruby in English. And what started out as a small project just sort of grew....

Ruby 版本

This book documents Version 1.6 of Ruby, which was released in September 2000.

Ruby version numbering follows the same scheme used for many other open source projects. Releases with even subversion numbers (1.0, 1.2, 1.4, and so on) are stable, public releases. These are the releases that are prepackaged and made available on the various Ruby Web sites.

Development versions of the software have odd subversion numbers, such as 1.1 and 1.3. These you'll have to download and build for yourself, as described in the box on page xxvii.

安裝 Ruby

You can get Ruby from ftp://ftp.netlab.co.jp/pub/lang/ruby, or from the mirror sites listed on page 526 in Appendix C. There you will find the latest stable release, as well as various development releases.

You'll always find source code releases of Ruby; you may also find prebuilt binaries for Windows or other operating systems (like the binary distribution of Ruby for Windows at http://www.pragmaticprogrammer.com/ruby/downloads/ruby-install.html).

Sidebar: 最新版的 Ruby

For those who just have to be on the very latest, hot-off-the-press and untested cutting edge (as we were while writing this book), you can get development versions straight from the developers' working repository.

The Ruby developers use CVS (Concurrent Version System, freely available from http://www.cvshome.com) as their revision control system. You can check files out as an anonymous user from their archive by executing the following CVS commands:

% cvs -d :pserver:anonymous@cvs.netlab.co.jp:/home/cvs
???login
(Logging in to anonymous@cvs.netlab.co.jp)
CVS password: guest
% cvs -d :pserver:anonymous@cvs.netlab.co.jp:/home/cvs
???checkout ruby

The complete source code tree, just as the developers last left it, will now be copied to a ``ruby'' subdirectory on your machine, updating your local source tree from a repository on the other side of the world. Isn't it a great time to be alive?

Building Ruby

In the Ruby distribution you'll find a file named README, which explains the installation procedure in detail. To summarize, you build Ruby on POSIX-based systems using the same four commands you use for most other open source applications: ./configure, make, make test, and make install. You can build Ruby under other environments (including Windows) by using a POSIX emulation environment such as cygwin [See http://sourceware.cygnus.com/cygwin for details.] or by using native compilers---see ``ntsetup.bat'' in the distribution's win32 subdirectory as a starting point.

運(yùn)行 Ruby

Now that Ruby is installed, you'd probably like to run some programs. Unlike compiled environments, there are two ways to run Ruby---interactively and as a program.

交互式 Ruby

The easiest way to run Ruby interactively is simply to type ``ruby'' at the shell prompt.

%?ruby
puts?"Hello,?world!"
^D
Hello,?world!

Here we typed in the single puts expression and an end of file character (which is control-D on our system). This process works, but it's sort of painful if you make a typo, and you can't really see what's going on as you type.

In the sample directory in the Ruby distribution you'll find a script named ``eval.rb''. It goes one step better by showing us the value of each expression as it is entered:

%?cd?sample
%?ruby?eval.rb
ruby>?a?=?"Hello,?world!"
"Hello,?world!"
ruby>?puts?a
Hello,?world!
nil
ruby>?^D
%

Here we can see the output from puts, and then the return value from puts (which is nil).

That's all fine and well, except that multiline expressions do not work, and you can't edit the line you're on, or go back and use previous lines (as you might with command history in a shell).

For the next step up from eval.rb, we have irb---Interactive Ruby. irb is a Ruby Shell, complete with command-line history, line editing capabilities, and job control. It is quite configurable and has many options, so much so that it has its own appendix beginning on page 517. We recommend that you get familiar with irb so you can try some of our examples interactively.

Ruby 程序

Finally, you can run a Ruby program from a file as you would any other shell script, Perl program, or Python program. You can simply run Ruby giving the script name as an argument:

%?ruby?myprog.rb

Or you can use the Unix ``shebang'' notation as the first line of the program file.[If your system supports it, you can avoid hard-coding the path to Ruby in the shebang line by using #!/usr/bin/env ruby, which will search your path for ruby and then execute it.]

#!/usr/local/bin/ruby?-w

puts?"Hello,?World!"

If you make this source file executable (using, for instance, chmod?+x?myprog.rb), Unix lets you run the file as a program:

%?./myprog.rb
Hello,?World!

You can do something similar under Microsoft Windows using file associations.

資源

Visit the Ruby Web sites, http://www.rubycentral.com and http://www.ruby-lang.org, to see what's new, and chat with other Ruby users on the newsgroup or mailing lists (see Appendix C).

And we'd certainly appreciate hearing from you. Comments, suggestions, errors in the text, and problems in the examples are all welcome. E-mail us at:

mailto:rubybook@pragmaticprogrammer.com

If you tell us about errors in the book, we'll add them to the errata list at:

http://www.pragmaticprogrammer.com/ruby/errata/errata.html

Finally, http://www.pragmaticprogrammer.com/ruby also contains the source code for almost all the book's examples, organized by page.

致謝

A book is a massive undertaking, one that we would never be able to complete without help from our all our friends, old and new. We're proud to count among our old friends the team at Addison-Wesley: Mike?Hendrickson, John?Fuller, the ever-helpful Julie?Steele, and the wonderful Julie?DiNicola. Thank you all.

Our reviewers were fantastic. We put them up against some incredibly tight deadlines and they came through for us. Reviewing a book full of technical detail isn't easy, so we're especially grateful to George?Coe, Bob?Davison, Jeff?Deifik, Hal?Fulton, Tadayoshi?Funaba, Clemens?Hintze, Kazuhiro?Hiwada, Kikutani?Makoto, Mike?Linksvayer, Aleksi?Niemel? Lew?Perin, Jared?Richardson, Armin?Roehrl, Conrad?Schneiker, Patrick?Schoenbach, and Eric?Vought. Thanks also go to the two Julies at Addison-Wesley for coordinating this truly international effort.

Several people helped us with specific areas of this book. Tadayoshi Funaba exchanged countless e-mails with us until we finally understood the Date module. Guy Decoux and Clemens Hintze patiently answered our questions about writing Ruby extensions, and Masaki Suketa helped us understand the WinOLE module.

Although much of the original Ruby documentation is in Japanese, there is a growing body of English translations, mostly undertaken by Japanese developers whose skills with English never cease to amaze us. Although there are too many individual contributions to this effort to name each author, we would like to single out Goto Kentaro, who has produced a large volume of high-quality documentation and placed it online.

Finally, we have to thank Yukihiro ``Matz'' Matsumoto, the creator of Ruby. We've lost count of the number of questions we've asked of him, and the number of patient and detailed answers he's sent back. As well as creating a truly wonderful language, Matz has fostered a wonderfully supportive and open culture in which that language can prosper.

Thank you all. Domo arigato gozaimasu.

Dave Thomas and Andy Hunt
THE PRAGMATIC PROGRAMMERS
http://www.pragmaticprogrammer.com

符號(hào)約定

Throughout this book, we use the following typographic notations.

Literal code examples are shown using a typewriter-like font:

class?SampleCode
??def?run
????#...
??end
end

Within the text, Fred#doIt is a reference to an instance method (doIt) of class Fred, while Fred.new [In some other Ruby documentation, you may see class methods written as Fred::new. This is perfectly valid Ruby syntax; we just happen to feel that Fred.new is less distracting to read.] is a class method, and Fred::EOF is a class constant.

The book contains many snippets of Ruby code. Where possible, we've tried to show what happens when they run. In simple cases, we show the value of expressions on the same line as the expression. For example:

a?=?1
b?=?2
a?+?b ?/td> 3

At times, we're also interested in the values of assignment statements, in which case we'll show them.

a?=?1 ?/td> 1
b?=?2 ?/td> 2
a?+?b ?/td> 3

If the program produces more complex output, we show it below the program code:

3.times?{?puts?"Hello!"?}
produces:
Hello!
Hello!
Hello!

In some of the library documentation, we wanted to show where spaces appear in the output. You'll see these spaces as ``[visible space]'' characters.

Command-line invocations are shown with literal text in a Roman font, and parameters you supply in an italic font. Optional elements are shown in large square brackets.

ruby [
            flags
            ]* [
            progname
            ] [
            arguments
            ]+


Extracted from the book "Programming Ruby - The Pragmatic Programmer's Guide"
Copyright ? 2001 by Addison Wesley Longman, Inc. This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/)).

Distribution of substantively modified versions of this document is prohibited without the explicit permission of the copyright holder.

Distribution of the work or derivative of the work in any standard (paper) book form is prohibited unless prior permission is obtained from the copyright holder.
Previous article: Next article: