#!/user/bin/ruby

# -*-coding:UTF-8-*-

class Customer

@@no_of_customers=0

def initialize(id,name,addr)

@cust_id=id

@cust_name=name

@cust_addr=addr

end

def display_details()

puts "Customer id #@cust_id"

puts "Customer name #@cust_name"

puts "Customer address #@cust_addr"

end

def total_no_of_customers()

@@no_of_customers +=1

puts "Total number of customers:#@@no_of_customers"

end

end

#创建对象

cust1=Customer.new("1","wen","文竹路")

cust2=Customer.new("2","fang","あり”

#调用方法

cust1.display_details()

cust1.total_no_of_customers()

cust2.display_details()

cust2.total_no_of_customers()

Ruby 类案例的更多相关文章

  1. 雷林鹏分享:Ruby 类案例

    Ruby 类案例 下面将创建一个名为 Customer 的 Ruby 类,您将声明两个方法: display_details:该方法用于显示客户的详细信息. total_no_of_customers ...

  2. 雷林鹏分享:Ruby 类和对象

    Ruby 类和对象 Ruby 是一种完美的面向对象编程语言.面向对象编程语言的特性包括: 数据封装 数据抽象 多态性 继承 这些特性将在 面向对象的 Ruby 中进行讨论. 一个面向对象的程序,涉及到 ...

  3. Ruby类

    Ruby类 类定义 #!/usr/bin/ruby class Sample def hello puts "Hello Ruby!" end end # 使用上面的类来创建对象 ...

  4. Ruby 类和对象

    Ruby 类和对象 Ruby 是一种完美的面向对象编程语言.面向对象编程语言的特性包括: 数据封装 数据抽象 多态性 继承 这些特性将在 面向对象的 Ruby 中进行讨论. 一个面向对象的程序,涉及到 ...

  5. Ruby类的继承

    Ruby继承的语法 class DerivedClass < BaseClass #some stuff end < 为继承符号 重写(override) 的概念 有时, 我们希望子类从父 ...

  6. Ruby类的创建与使用

    Ruby是一种面向对象编程语言,这意味着它操纵的编程结构称为"对象" 先上代码, 了解类的定义与使用方式 class Computer $manufacturer = " ...

  7. Ruby类,模块1

    类的扩展和继承 class Fixnum def dosome(str) puts str end def abs puts "覆盖了原有的方法" end end puts 1.c ...

  8. ruby 类创建-继承-消息

    ############################################# #create ruby a class #@符号表示实例变量,相当于java的private 属性 ### ...

  9. Ruby类扩张(extension)

    创建: 2017/09/07 更新: 2017/09/16 修改标题字母大小写 ruby ---> Ruby    扩张类  class 类名     扩张的内容  end           ...

随机推荐

  1. CentOS下强行umount卸载设备

    fuser -cu /usr/local/tomcat7/webapps/dsideal_yy/html/down/ fuser -ck /usr/local/tomcat7/webapps/dsid ...

  2. 51nod算法马拉松14

    这次太丢人了只搞出来了A到D,那就将就写一写A到D... A 棋盘问题 脑筋急转弯题,不难发现每一次两个人只能染白奇数个格子,所以数数有奇数还是偶数个白格子就行了. #include<cstdi ...

  3. windows2008 IIS下配置FTP服务

    一.服务器管理器 1.2008的系统使用服务器管理器,选择角色,因为我之前已经开启了IIS服务器角色,所以我现在只要添加角色服务即可,如果你没有开启过的话,直接添加角色即可. 2.选择WEB服务器,打 ...

  4. HDU 2955(0-1背包问题)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/M 题目: Description The aspir ...

  5. vim operation

    note:  转自 www.quora.com ,很好的网站. 具体链接如下: https://www.quora.com/What-are-some-impressive-demos-of-Vim- ...

  6. Hbuider 同步github

    别人的教程,仅作收藏. http://blog.csdn.net/u011871921/article/details/44238971

  7. .net 设置导航的当前状态

    1.静态地址共用母版页时,加当前页的状态(使用加参数的方法实现): a: main.Master为链接设参数 MenuId <li> <a <%=MenuId==?" ...

  8. 集中式版本控制VS分布式版本控制

    CVS及SVN都是集中式的版本控制系统,而Git是分布式版本控制系统,集中式和分布式版本控制系统有什么区别呢? 集中式版本控制系统,版本库是集中存放在中央服务器的,而干活的时候,用的都是自己的电脑,所 ...

  9. bzoj4518: [Sdoi2016]征途--斜率DP

    题目大意:把一个数列分成m段,计算每段的和sum,求所有的sum的方差,使其最小. 由方差*m可以化简得ans=m*sigma(ki^2)-sum[n]^2 很容易得出f[i][j]=min{f[i- ...

  10. 一个链接直接打开APP

    http://www.cnblogs.com/jzm17173/p/4569574.html 这是IOS http://www.jianshu.com/p/af211f2a990e