#!/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. 《隆重介绍 思源黑体:一款Pan-CJK 开源字体》

    关于思源黑体 思源黑体是谷歌与 Adobe 联合开发,支持简体中文.繁体中文.日文.韩文以及英文:支持 ExtraLight.Light.Normal.Regular.Medium.Bold 和 He ...

  2. jq prepend() 方法在被选元素的开头(仍位于内部)插入指定内容。 提示:prepend() 和 prependTo() 方法作用相同。差异在于语法:内容和选择器的位置,以及 prependTo() 无法使用函数来插入内容。

    <html><head><script type="text/javascript" src="/jquery/jquery.js" ...

  3. 20145308刘昊阳 《Java程序设计》第7周学习总结

    20145308刘昊阳 <Java程序设计>第7周学习总结 教材学习内容总结 第13章 时间与日期 13.1 认识时间与日期 13.1.1 时间的度量 格林威治时间(GMT) 世界时(UT ...

  4. CentOS6.4 访问域局网中Windows的共享

    mount -t cifs -o username=" //10.10.3.246/f /usr/local/openresty/nginx/html/down 说明: mount -t c ...

  5. Codeforces Round #195 (Div. 2) A. Vasily the Bear and Triangle

    水题,注意数据范围即可 #include <iostream> #include <algorithm> #include <utility> using name ...

  6. [知识点]SPFA算法

    // 此博文为迁移而来,写于2015年4月9日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102vx93.html 1.前言 ...

  7. 【搬运工】NOIP吧置顶贴

    目的是存置顶贴里的链接.. 原帖:http://tieba.baidu.com/p/1753284199 资源站:*C++资源:http://tieba.baidu.com/p/1239792581* ...

  8. java分享第一天(java环境及原理)

    1 JDK的安装目录中:环境变量中增加JAVA_HOME变量:JDK安装目录:在path中添加JDK的bin目录 2 java执行的顺序是: 1 用java编译器javac   XXX.java   ...

  9. bootstrap如何给.list-group加上序号

    在bootstrap中,我们可以使用不带任何class的<ol>跟<li>来创建一个有序列表,但是如果加上list-group类,样式有了,但列表前面的数字却没了. Boots ...

  10. [LintCode] Submatrix Sum 子矩阵之和

    Given an integer matrix, find a submatrix where the sum of numbers is zero. Your code should return ...