简单教程
提交运行
代码编辑器:
# !/usr/bin/ruby -w # -*- encoding:utf-8 -*- # filename: main.rb # author: 简单教程(www.twle.cn) # Copyright © 2015-2065 www.twle.cn. All rights reserved. class Company @@no_of_company = 0 def initialize(id, name, addr) @comp_id=id @comp_name=name @comp_addr=addr @@no_of_company += 1 end def display_details() puts "Company id #@comp_id" puts "Company name #@comp_name" puts "Company address #@comp_addr" end def total_no_of_company() puts "Total number of company: #@@no_of_company" end end comp1=Company.new(1, "百度", "北京市海淀区") comp1.total_no_of_company() comp2=Company.new(2, "简单教程", "北京市东城区") comp2.total_no_of_company()
运行结果: