Perish

博客园 首页 联系 订阅 管理

2012年7月4日

摘要: Ruby语言中,以对象为基本单位,可以说所有的元素都是对象。按照之前对于面向对象程序的理解,对象是指包含了特定属性和方法集合的一组程序。对象由类来定义,具体的表现为对象实例。也就是说,对象是类的实例化[2]。Ruby语言的基础元素对象:数值对象、字符串对象、正则表达式对象、时间对象、文件对象、目录对象、数组、哈希、例外对象等数值对象 由于Ruby中一切数据都是对象,所以我们处理的数字实际上也是对象。 a = 10,这样一个简单的赋值语句,实际上应当理解为 a = Numeric.new(10) 这样的一种实例化形式。变量:局部变量(小写字母或_开头)、全局变量($)、实例变量(@)、类变量(. 阅读全文
posted @ 2012-07-04 17:31 ---小青年--- 阅读(266) 评论(0) 推荐(0)

摘要: from_file, to_file = ARGVscript = $0puts "Copying from #{from_file} to #{to_file}"input= File.open(from_file)indata = input.read()puts "the input file is #{indata.length} bytes long."puts "Does the output file exist? #{File.exists? to_file} "puts "Ready , hit RETUR 阅读全文
posted @ 2012-07-04 16:45 ---小青年--- 阅读(180) 评论(0) 推荐(0)

2012年7月2日

摘要: user = ARGV.firstprompt = '>'puts "Hi #{user}, I'm the #{$0} script."puts "I'd like to ask you a few questions."puts "Do you like me #{user}?"print promptlikes = STDIN.gets.chomp()puts "where do you live #{user}?"print promptlives = STDIN.ge 阅读全文
posted @ 2012-07-02 18:18 ---小青年--- 阅读(543) 评论(0) 推荐(1)

2012年6月30日

摘要: 例子1:print "How old are you ?"age = gets.chomp()print "How tall are you ?"height = getsprint "How much do you weight ?"weight = gets.chomp()puts "so, you're #{age} old, #{height} tall and #{weight} heavy."输出的内容如下所示:How old are you ?11How tall are you ?23How 阅读全文
posted @ 2012-06-30 20:04 ---小青年--- 阅读(458) 评论(0) 推荐(0)