ruby學(xué)習(xí)筆記(1)

          發(fā)現(xiàn)了這個學(xué)習(xí)ruby的好地方,每天就盡量抽點(diǎn)時(shí)間學(xué)習(xí)一下吧。
          http://www.rubylearning.com/forum/

          今天學(xué)習(xí)第一課,比較簡單.

          1.1 Introduction
                簡介ruby
              
          1.2
          Installation
                1)
          Downloading Ruby and an Editor
                      下載地址: Ruby Installer for Windows
                       安裝包中包括一個ruby的編輯器SciTE.            

                 2)Ruby Programming Environment:            
                       假設(shè)我們裝在C:/ruby目錄下,系統(tǒng)將創(chuàng)建一些新的文件夾。
                    
                      c:/ruby/bin:ruby子帶的命令以及可執(zhí)行文件
                      c:
          /ruby/lib/ruby/1.8:ruby的一些標(biāo)準(zhǔn)庫
                      c:
          /ruby/lib/ruby/1.8/i386-mswin32:與平臺相關(guān)聯(lián)的庫
                      c:
          /ruby/lib/ruby/site_ruby: 存放工具庫或第三方庫
                      c:
          /ruby/lib/ruby/gems: Ruby-Gems 包目錄.
                      c:
          /ruby/src:ruby代碼目錄.
                      c:
          /ruby/samples/RubySrc-1.8.6/sample: ruby例子代碼目錄.      

          1.3 First Ruby program
                      1) 可以使用ruby自帶的
          SciTE.作為編輯器(程序->ruby->SciTE). 對于SciTE,使用F8打開輸出,F(xiàn)5運(yùn)行ruby程序
                      2) ruby的文件一般以.rb后綴
                      3) 經(jīng)典的hellowor!(在SciTE中新建文件hello.rb,然后輸入)
                              puts 'Hello ' + "world " + 'ruby!'
                      4)  總結(jié):
                             a. 不需要main方法或者函數(shù)
                             b. 字符串可以用‘’ 、“”
                             c. ruby是腳本語言,直接運(yùn)行,不需要編譯
                             d. ruby的命名規(guī)范建議文件名為小寫,如Foo class命名foo.rb

          1.4 Features of Ruby
                     1) 大小寫敏感
                     2) 單行注釋可以用#,多行注釋可以用=begin開始,=end結(jié)束
                     3) 一行中的多行代碼必須用;分割
                     4)使用\轉(zhuǎn)義 或者  連接多行

          1.5
          Numbers in Ruby
                     在ruby中,帶.的
          數(shù)稱為浮點(diǎn)數(shù),不帶.的數(shù)稱為整數(shù)
                      1) 整數(shù)和整數(shù)的操作結(jié)果為整數(shù)
                      2) ruby使用
          Fixnum(默認(rèn))和Bignum處理超大數(shù)
                      3) 繼承結(jié)構(gòu):
                                                   Object
                                                        |
                                                   Numric
                                                |              |
                                           Integer      Float
                                                |
                                    Bignum  Fixnum

          1.6 String fundamentals
                    在ruby中,ruby作為bytes的序列存儲,不像java的String不可修改
                   1) 字符串可以使用“ ”或者' ',但' '更有效
                   2) 使用\轉(zhuǎn)義
                   3) 可以使用` ` 執(zhí)行Console 命令, 如 puts `dir`等

          1.7
          Variables and Assignment
                   在ruby中,當(dāng)解釋器判斷到賦值符號=,就認(rèn)為存在一個變量.
                    1) 局部變量由_或者小寫字母開頭,由字母、數(shù)字、下劃線組成
                    2) << 可以向一個字符串中添加字符串,如
          a = 'hello '; a<<'world.
           

          1.8 總結(jié):(原網(wǎng)站上的總結(jié),很容易理解)
             * We are discussing about Ruby 1.8.6 on a Windows platform.
              
          * Ruby is an interpreted language
              
          * In Ruby, there's always more than one way to solve a given problem.
              * The code examples would be run in the SciTE editor and ensure that you have done the relevant settings as mentioned on the page "First Ruby program".
              
          * All Ruby source files have the .rb file extension.
              
          * In Ruby, program execution proceeds in general from top to bottom.
              
          * Features: Free format, Case sensitive, Two type of comments, Statement delimiters are not required, Around 38 Keywords
              
          * You may be used to thinking that a false value may be represented as a zero, a null string, a null character, or various other things. But in Ruby, all of these are true; in fact, everything is true except the reserved words false and nil.
              
          * We shall be referring to the documentation here - http://www.ruby-doc.org/core/
              * puts (s in puts stands for string; puts really means put string) simply writes onto the screen whatever comes after it, but then it also automatically goes to the next line.
              
          * Parentheses are usually optional with a method call. These calls are all valid:
                foobar
                foobar()
                foobar(a, b, c)
                foobar a, b, c
              
          * In Ruby, numbers without decimal points are called integers, and numbers with decimal points are usually called floating-point numbers or, more simply, floats (you must place at least one digit before the decimal point).
              
          * Some very common Ruby operators:+ addition; - subtraction; * multiplication; / division
              
          * The increment and decrement operators (++ and --) are not available in Ruby, neither in "pre" nor "post" forms.
              
          * Anything inside brackets is calculated first (or, more technically, given higher precedence).
              
          * Observe how the modulus operator (%) works in Ruby.
              
          * When you do arithmetic with integers, you'll get integer answers.
              * String literals are sequences of characters between single or double quotation marks.
              
          * In Ruby, strings are mutable. They can expand as needed, without using much time and memory.
              
          * String concatenation is joining of two strings, using the + operator.
              
          * Escape sequence is the \ character. Examples: \", \\, \n
              * '' is an empty string.
              
          * If you get a compilation error like -
                #
          <TypeError: can't convert Fixnum into String>
                it means that you can't really add a number to a string, or multiply a string by another string.
              * Constants begin with capital letters. Example PI, Length
              
          * A variable springs into existence as soon as the interpreter sees an assignment to that variable. It is a good practice to assign nil to a variable initially.
              
          * x, y = y, x will interchange the values of x and y.
              
          * Local variables must start with either a lowercase letter or the underscore character (_), and they must consist entirely of letters, numbers, and underscores.Examples: india, _usa, some_var
              
          * .to_i, .to_f, .to_s are used to convert to an integer, float, string respectively.
              
          * The operator << is used to append to a string

          posted on 2007-09-28 18:26 想飛就飛 閱讀(4836) 評論(4)  編輯  收藏 所屬分類: ROR

          評論

          # re: ruby學(xué)習(xí)筆記(1) 2007-09-29 15:56 mudong

          哥們 繼續(xù)寫   回復(fù)  更多評論   

          # re: ruby學(xué)習(xí)筆記(1) 2007-10-10 21:18 雪兒

          寫的很好 繼續(xù)啊!! 期待中  回復(fù)  更多評論   

          # re: ruby學(xué)習(xí)筆記(1)[未登錄] 2008-01-29 12:15 呵呵

          很不錯  回復(fù)  更多評論   

          # re: ruby學(xué)習(xí)筆記(1) 2009-04-07 13:48 coolfish

          多謝分享,贊一個。
          繼續(xù)寫。
            回復(fù)  更多評論   

          公告


          導(dǎo)航

          <2007年9月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          23242526272829
          30123456

          統(tǒng)計(jì)

          常用鏈接

          留言簿(13)

          我參與的團(tuán)隊(duì)

          隨筆分類(69)

          隨筆檔案(68)

          最新隨筆

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 云和县| 昌黎县| 页游| 怀远县| 巩留县| 宁夏| 图木舒克市| 蒲城县| 静海县| 楚雄市| 长兴县| 石景山区| 冕宁县| 肇庆市| 东城区| 梁河县| 启东市| 麦盖提县| 永福县| 额济纳旗| 古蔺县| 永康市| 姚安县| 阜新| 大石桥市| 舞阳县| 开远市| 遂昌县| 惠安县| 桂平市| 阳山县| 卓尼县| 亳州市| 东港市| 洞头县| 根河市| 江达县| 灵山县| 旌德县| 宜兰县| 靖远县|