Ruby学习笔记
一、语法记录
Constant
常量名(类名、模块名,大写开头)
variable
变量名(方法名,小写开头)
def f ... end
方法
def f(x) x end
最后语句即return
f
调用无参数的方法
f(1)
调用带参数的方法
class A ... end
类
class A def initialize(a, b, c) end end
构造函数
a = A.new(5)
构造对象
x = 3
局部变量(方法作用域)
$x = 3
全局变量(全局作用域)
@x = 3
实例变量,对象变量(当前对象作用域)
@@x = 3
类变量(类作用域)
class A def name @name end end
成员函数
puts a.f
调用无参数的成员函数(getter)
class A def self.f end end
class A def A.f end end
类方法
class A<B end
继承
class String def length 20 end end
覆写
class A def f1 end private def f2 end public def f3 end end
声明私有和公有方法(放在定义前)
private :f1, :f2; protected :f3
声明私有和受保护方法(放在定义后)
Pi = 3.141592
常量(类作用域)
module A end
模块(不可继承和实例化的类)
class A include B end
渗入
二、参考资料
* 《Ruby从入门到精通》
Beginning Ruby : From Novice to Professional
* ruby-doc
三、开发工具
* Aptana
http://www.aptana.com/products/radrails
三、开发库
* DxRuby
本文介绍了Ruby编程语言的基础语法,包括常量、变量、方法、类等核心概念,并提供了丰富的示例代码。此外还推荐了一些学习资源和开发工具。
649

被折叠的 条评论
为什么被折叠?



