解釋性語言,自上而下執行,純面向物件,跨平臺,動態繫結,沒有多重繼承。
NetBeans sun公司開發
irb指令可快速實時輸入並返回結果 quit 或者exit
rdoc hello.rb 生成html文件
rdoc -f chm 生成chm文件,依賴月微軟的html help workshop
gem ruby包管理
gem list列出已經安裝的包
gem install 安裝包
gem uninstall 解除安裝安裝包
gem query 搜尋包
gem help 使用幫助
rebyscript2exe 和exerb 可一個把ruby轉換為脫離環境 獨立執行檔案的工具。
命名規則
區域性變數以小寫字母或者下劃線開頭。
全域性變數以美元符號$開頭。
例項變數以@開頭。
類變數以@@開頭。
常量或類名以大寫字母開頭。
關鍵字
module 模組定義
class 類
def,undef 方法
defined? 檢查型別
if,then,else,elsif,case,when,unless 條件語句
for,in,while,until,next(continue),break,do,redo(重複當前迴圈週期),retry(重複整個迭代迴圈),yield 迴圈語句
not,and,or 邏輯判斷
nil 空值
rescue,ensure 異常處理
super,self 物件引用
begin/end 塊的起始結束
BEGIN,END 嵌入模組
_FILE_,_LINE_ 檔案相關
alias 別名
nil與c#的null類似,ruby在邏輯判斷中,只有nil和false表示假,其他所有表示式都表示真。
public,protected,private 子類可以在內部使用父類的protected和private,C#中只可以訪問protected
class BaseClass
def public_m1()
puts "basePublic"
end
protected
def protected_m2()
puts "baseProtected"
end
private
def private_method()
puts "basePrivate"
end
end
class MyClass<BaseClass
def call_basepublic()
public_m1
end
def call_baseprotected()
protected_m2
end
def call_baseprivat()
private_method
end
end
#baseclass=BaseClass.new
#baseclass.private_method 私用不能訪問
#baseclass.protected_m2 受保護也不能訪問
myclass=MyClass.new
myclass.call_baseprivat
myclass.call_baseprotected
myclass.call_basepublic