ruby 文法的總結

來源:互聯網
上載者:User
沒有函數,用了半天的時間弄環境,用了半天的時間熟悉文法,函數可以自己去查手冊函數查的網頁在http://www.rubycentral.com/ref/index.html 函數庫官方站在http://www.ruby-lang.org/
編寫工具在 win下使用http://homepage2.nifty.com/sakazuki/rde_e.htmlclass A
 def initialize(name,age) #初始化
 @name = name;
 @age  = age;
 puts "i am parent";
 end
end
class A                  #直接在類裡添加方法
  def to()
  return @name;
  end
end
 #na =A.new('aaa','');    #聲名
 #puts na.to_s            #得到類id
 #puts na.inspect         #
 #puts na.to();
 class B < A
  def initialize(name='',age='')
  super(name,age);        #初始化夫類方法
  end
  def abc()
    puts "i am child!";
  end
 end
 #def na.to()              #重載
  #return "456789";
 #end
 #puts na.to();
 #b=B.new();
 #b.abc;
 
 #模組使用
 module M
  def bm
    b=B.new();
    return "sadf";
  end
 end
#require "M";
include M;
M.bm();
 #模組使用結束
 begin
    #執行程式
    rescue#發生異常
      retry#重新執行begin
    ensure  #是否發生異常都要執行
 end
 #
 #puts m.bm();
 #b.abc();
 #include M;
 #Object;
 #b.abc();
 i=30;
 case i;
 when 0...5
      print '1';
 when 6...20
      print '2';
 when 11...20
      print '3';
 end
=begin   大段注釋
 retry   重新回到迴圈開始
 yield   代表程式塊調用
while (i<19)
  if i==3
  puts('y');
  #end
  #unless i==3 #為false 運行
  #puts('n');
  #end
  #i=i+1;
end
=end
exit(1);
until i<19 #為false 運行
  puts i;
  i=i+1;
end

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.