博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ruby学习--varaible
阅读量:6852 次
发布时间:2019-06-26

本文共 1256 字,大约阅读时间需要 4 分钟。

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

 

转载于:https://www.cnblogs.com/yizihan/p/3940036.html

你可能感兴趣的文章
java abstract class和interface有什么区别
查看>>
虚拟机桥接模式不能上网
查看>>
lodash.js 学习记录
查看>>
1.4 Genymotion模拟器安装
查看>>
简说设计模式——外观模式
查看>>
简说设计模式——模板方法模式
查看>>
php 图片写字
查看>>
linux之权限
查看>>
Deep Learning(深度学习)学习笔记整理系列之(三)
查看>>
网页布局之Div vs Table (2)
查看>>
可变参数列表
查看>>
BouncyCastle.Crypto的RSA算法调用源码
查看>>
vs2017 + Python3.6 +Django1.11 连接mysql数据库
查看>>
一张思维导图带你梳理HashMap相关知识
查看>>
MVC 从Excel导入到DataTable
查看>>
Symbol
查看>>
Selenium WebDriver + IE11 问题汇总
查看>>
Oracle数据库设置Scott登录
查看>>
IOS开发之UIScrollVIew运用
查看>>
iOS 基础-----关于UIView 的 frame 与 bounds
查看>>