ruby学习--varaible
#全局变量
$global_variable=10
class Class1
def print_global()
puts "Global variable in Class1 is #{$global_variable}"
end
end
class1obj=Class1.new
class1obj.print_global()
#实例变量
class Customer
def initialize(id,name,addr)
@cust_id=id
@cust_name=name
@cust_addr=addr
end
def display_detalis
puts "Customer id #{@cust_id}"
puts "Customer name #{@cust_name}"
puts "Customer addr #{@cust_addr}"
end
end
cust1=Customer.new("","John","Wisdom")
cust1.display_detalis
#类变量
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 addr #{@cust_addr}"
end
def total_no_of_customers()
@@no_of_customers +=1
puts "Totla number of customers:#{@@no_of_customers}"
end
end
cust1=Customer.new("","John","Wisdom")
cust2=Customer.new("","Poul","New") cust1.total_no_of_customers
cust2.total_no_of_customers
ruby学习--varaible的更多相关文章
- ruby 学习笔记 1
写ruby blog 系统的记录下.也是对我学ruby的点滴记录. 先介绍下我的学习环境.系统:ubuntu12.04文档:techotopia ,ruby文档,the hard way learn ...
- Ruby学习心得之 Linux下搭建Ruby环境
作者:枫雪庭 出处:http://www.cnblogs.com/FengXueTing-px/ 欢迎转载 Ruby学习心得之 Linux下搭建Ruby环境1.前言2.Linux下安装Ruby环境 一 ...
- Ruby学习之mixin
直接上代码: module Action def jump @distance = rand(4) + 2 puts "I jumped forward #{@distance} feet! ...
- ruby学习网站
Ruby官方中文网(推荐): https://www.ruby-lang.org/zh_cn/ 国内非常不错的Ruby学习教程网站(推荐): http://www.yiibai.com/ruby Ru ...
- Ruby学习笔记4: 动态web app的建立
Ruby学习笔记4: 动态web app的建立 We will first build the Categories page. This page contains topics like Art, ...
- ruby学习笔记(1)-puts,p,print的区别
ruby学习笔记-puts,p,print的区别 共同点:都是用来屏幕输出的. 不同点:puts 输出内容后,会自动换行(如果内容参数为空,则仅输出一个换行符号):另外如果内容参数中有转义符,输出时将 ...
- Ruby学习资源汇总
from:http://segmentfault.com/a/1190000000362058 Ruby 语言 Try Ruby: 无需在你的系统中安装.Ruby,只要通过浏览器便可立即体验 Ruby ...
- Ruby学习之深入类
在讨论对象模型时,对类做了初步了解,关于类本身,还有许多知识需要学习. 类定义 Ruby中,可以用class关键字或者Class.new方法来定义一个类,在Ruby中,类定义的同时就是在运行代码,类和 ...
- Ruby学习之代码块
代码块在其他的语言中都或多或少接触过一些,如perl中sort{$a<=>$b}keys,传入代码块实现按数值排序,在swift中用到闭包,更加深入学习到training closure. ...
随机推荐
- Linux下getopt()函数的简单使用
最近在弄Linux C编程,本科的时候没好好学啊,希望学弟学妹们引以为鉴. 好了,虽然啰嗦了点,但确实是忠告.步入正题: 我们的主角----getopt()函数. 英雄不问出处,getopt()函数的 ...
- MFC中修改静态文本框中文字的字体、颜色
假设有一个静态文本框控件,其ID为:IDC_STATIC_XSDJ,且关联一个control类的CStatic类型的变量m_static_xsdj. 设置字体时自然要用到CFont类,下面介绍两种方法 ...
- 为什么SSL证书流量暴增?
网络服务提供商 Sandvine 近日发布了一份报告,中提到了一个非常有趣的现象:和去年的数据相比,加密网络流量(SSL)在今年正在呈现出爆发式增长. 这个变化在欧洲表现得十分明显:和去年的 1.47 ...
- cocos2d_x iconv转码
作者:何卫 转载请注明,原文链接:http://www.cnblogs.com/hewei2012/p/3374147.html iconv下载(Android) 源码下载地址,已编译完的iconv包 ...
- Animated Scroll to Top
Due to a number of requests, I'm writing a detail tutorial on how to create an animated scroll to to ...
- MySQL通配符过滤
在WHERE后使用LIKE操作符能够进行通配符过滤: products表例如以下: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGl1eWluZ18xM ...
- 做什么都要坚持,写blog也一样,
2015年一篇文章没写,惭愧,时间过的真快 好习惯要坚持,
- 解决黑苹果与windows时区不一致
原理就是将windows识别硬件时间为UTC-0而不是现在的UTC+8 下面都是抄来的 注册表HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\T ...
- Codeforces Round #140 (Div. 1) D. The table 构造
D. The table 题目连接: http://www.codeforces.com/contest/226/problem/D Description Harry Potter has a di ...
- asmack
https://github.com/zhuqizhi/tlbs1409 https://github.com/maxting/IM_Project150126 https://github.com/ ...