<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    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)

    最新隨筆

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 免费人成再在线观看网站| 亚洲永久在线观看| 免费的黄色的网站| 亚洲国产精品成人网址天堂| 国产精品亚洲精品日韩动图| 热久久精品免费视频| 久久人午夜亚洲精品无码区| 国产又长又粗又爽免费视频| www成人免费视频| 国产亚洲精品美女久久久| 香蕉免费一区二区三区| 久久久久亚洲精品日久生情 | 一个人看的在线免费视频| 亚洲国产精品成人久久蜜臀| 精品无码一级毛片免费视频观看 | 黄色免费网址大全| 亚洲免费在线观看| 国产成人久久AV免费| 亚洲国产成人综合| 尤物永久免费AV无码网站| 一个人看的免费观看日本视频www| 亚洲国产精华液网站w| 69式互添免费视频| 亚洲av色香蕉一区二区三区| 亚洲成网777777国产精品| 玖玖在线免费视频| 亚洲13又紧又嫩又水多| 全部免费毛片在线| 国色精品va在线观看免费视频| 久久久婷婷五月亚洲97号色 | 日本高清免费观看| 亚洲AV无码无限在线观看不卡| 亚洲国产91精品无码专区| 久久w5ww成w人免费| 久久精品国产亚洲AV电影网| 亚洲伊人色欲综合网| 免费无码精品黄AV电影| aa在线免费观看| 最新亚洲精品国偷自产在线| 久久精品国产亚洲5555| 青草草色A免费观看在线|