ruby學習筆記(1)

          發現了這個學習ruby的好地方,每天就盡量抽點時間學習一下吧。
          http://www.rubylearning.com/forum/

          今天學習第一課,比較簡單.

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

                 2)Ruby Programming Environment:            
                       假設我們裝在C:/ruby目錄下,系統將創建一些新的文件夾。
                    
                      c:/ruby/bin:ruby子帶的命令以及可執行文件
                      c:
          /ruby/lib/ruby/1.8:ruby的一些標準庫
                      c:
          /ruby/lib/ruby/1.8/i386-mswin32:與平臺相關聯的庫
                      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打開輸出,F5運行ruby程序
                      2) ruby的文件一般以.rb后綴
                      3) 經典的hellowor!(在SciTE中新建文件hello.rb,然后輸入)
                              puts 'Hello ' + "world " + 'ruby!'
                      4)  總結:
                             a. 不需要main方法或者函數
                             b. 字符串可以用‘’ 、“”
                             c. ruby是腳本語言,直接運行,不需要編譯
                             d. ruby的命名規范建議文件名為小寫,如Foo class命名foo.rb

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

          1.5
          Numbers in Ruby
                     在ruby中,帶.的
          稱為浮點數,不帶.的數稱為整數
                      1) 整數和整數的操作結果為整數
                      2) ruby使用
          Fixnum(默認)和Bignum處理超大數
                      3) 繼承結構:
                                                   Object
                                                        |
                                                   Numric
                                                |              |
                                           Integer      Float
                                                |
                                    Bignum  Fixnum

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

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

          1.8 總結:(原網站上的總結,很容易理解)
             * 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學習筆記(1) 2007-09-29 15:56 mudong

          哥們 繼續寫   回復  更多評論   

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

          寫的很好 繼續啊!! 期待中  回復  更多評論   

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

          很不錯  回復  更多評論   

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

          多謝分享,贊一個。
          繼續寫。
            回復  更多評論   

          公告


          導航

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

          統計

          常用鏈接

          留言簿(13)

          我參與的團隊

          隨筆分類(69)

          隨筆檔案(68)

          最新隨筆

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 分宜县| 通海县| 呼玛县| 德庆县| 勃利县| 治多县| 南投市| 托克托县| 法库县| 吉首市| 秀山| 寻甸| 扶风县| 北海市| 洪江市| 晋州市| 皮山县| 淮阳县| 星座| 沙洋县| 遂溪县| 石嘴山市| 阳山县| 卓资县| 湖口县| 屯昌县| 石棉县| 侯马市| 奈曼旗| 嘉祥县| 鱼台县| 梁河县| 青龙| 昭苏县| 中宁县| 兰州市| 合作市| 罗田县| 颍上县| 综艺| 威信县|