从06年10月开始接触Ruby,眨眼间已经过了3年半了。虽然用了这么久,感觉真的不是很精通。虽然已经过了而立之年,但感觉自己还是太浮躁了。浪费了好多时光在游戏上。
买了好久的《The Ruby Way(第二版)》,只是当作工具书,没有仔细读过。终于决定好好的把这本书读一遍。今天看了第一章,确实有不少收益。
Class是一个对象,而Object是一个类。作者把这句话强调了好多次。
class Myclass
@x = 1 # 类实例变量,类对象MyClass的属性,MyClass本身就是个实例
def mymethod # 实例方法是无法访问类实例变量的
puts @x # 实例变量
end
def self.mymethod
puts @x
end
end
c = Myclass.new
c.mymethod # 由于实例变量没有被赋值,所以结果是nil
Myclass.mymethod # 类方法可以访问类实例变量,结果是1
单例类(继承单个实例的匿名类)。终于搞懂了原来这样生成的是单例类。
str = "hello"
class << str
def hyphenated
self.split("").join("-")
end
end
str.hyphenated # "h-e-l-l-o"
Proc对象。从来没有这么写过。
def power(e)
proc {|base| base**e}
end
square = power(2)
cube = power(3)
a = square.call(11) # 结果是 121
b = square.call(5) # 结果是 25
c = cube.call(6) # 结果是 216
d = square.call(11) # 结果是 512
分享到:
相关推荐
The Ruby Way(第2版) <br>The Ruby Way assumes that the reader is already familiar with the subject matter. Using many code samples it focuses on "how-to use Ruby" for specific applications, either ...
The Ruby Way 第三版(英文版),全书22章,书中包含600多个按主题分类的示例。每个示例都回答了“如何使用Ruby来完成”的问题。 ——Ruby on Rails之父David Heinemeier Hansson倾力推荐!
the ruby way 2ed. the ruby way 2ed.
《The Ruby Way 第二版》中文版采用“如何解决问题”的方式阐述Ruby编程,书中包含400多个按主题分类的示例。每个示例都回答了“如何使用Ruby来完成”的问题。首先对要完成的任务进行了描述,并讨论了技术方面的约束...
the ruby way the ruby way
11.5 时间日期the ruby way.rar
内含以下4个文档: 1、Addison.Wesley.The.Ruby.Way.2nd.Edition.Oct.2006.chm 2、O'Reilly.Learning.Ruby.May.2007.chm 3、Programming Ruby 2e.pdf 4、ruby中文文档.chm
The Ruby Way(处理文件和目录)
TheRubyWay(Ruby之道)英文版 Addison.Wesley.The.Ruby.Way.2nd.Edition.Oct.2006.pdf
the ruby way,ruby 入门经典
Addison Wesley The Ruby Way 2Nd Edition Oct 2006.pdf(英文版)
关于ruby的电子书,CHM格式 《The ruby way》这本书例子比较多!
Ruby is a fully object-oriented, dynamic scripting language which borrows some of the best features from LISP, Smalltalk, Perl, CLU, and other languages, and blends them into a harmonious whole. The ...
Shaw is the author of the popular online books Learn Python the Hard Way, Learn Ruby the Hard Way, and Learn C the Hard Way. He is also the creator of several open source software projects like ...
The Ruby Programming Language 2008 (English)包含精致书签,可复制文档内容,结合中文版可以对ruby相关语法进行学习,个人感觉ruby很大,死读书不如结合一些实例进行了解更好,本手册更适合遇到问题再来翻阅
2008新作,是英文版啊. Ruby的作者的作品, part.1 一共两个压缩包 Part 2在http://download.csdn.net/source/424089
实在是没有中文资料,就跟一哥们搞了些英文资料,有兴趣的就学学吧.