ruby學習--varaible

來源:互聯網
上載者:User

標籤:style   blog   color   ar   div   log   sp   new   ad   

1 #全域變數2 $global_variable=103 class Class14     def print_global()5         puts "Global variable in Class1 is #{$global_variable}"6     end7 end8 class1obj=Class1.new9 class1obj.print_global()
 1 #執行個體變數 2 class Customer 3     def initialize(id,name,addr) 4         @cust_id=id 5         @cust_name=name  6         @cust_addr=addr 7     end 8     def display_detalis 9         puts "Customer id #{@cust_id}"10         puts "Customer name #{@cust_name}"11         puts "Customer addr #{@cust_addr}"12     end13 end14 cust1=Customer.new("1","John","Wisdom")15 cust1.display_detalis
 1 #類變數 2 class Customer 3     @@no_of_customers=0 4     def initialize(id,name,addr) 5         @cust_id=id 6         @cust_name=name 7         @cust_addr=addr 8     end 9     def display_details()10         puts "Customer id #{@cust_id}"11         puts "Customer name #{@cust_name}"12         puts "Customer addr #{@cust_addr}"13     end14     def total_no_of_customers()15         @@no_of_customers +=116         puts "Totla number of customers:#{@@no_of_customers}"17     end18 end19 cust1=Customer.new("1","John","Wisdom")20 cust2=Customer.new("2","Poul","New")21 22 cust1.total_no_of_customers23 cust2.total_no_of_customers

 

ruby學習--varaible

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.