最近的Ruby for Rails读书笔记

1,module的mix-in
两个module定义同一方法,都include后,后include的module的方法有效

2,全局变量以$开头
Ruby自带的全局变量有
$:表示在你load外部文件时Ruby搜索的path
$$表示Ruby进程ID

3,self的指代
Context                         Example                               Which object is self?
Top level of program   Any code outside of other blocks        main(built-in top-level default object)
Class definition       class C                                 The class object C
Module definition      module M                                The module object M
Method definitions     1. Top level                            main(built-in top-level default object)
                          def method_name
                       2. Instance method definition           An instance of C, responding to method_name
                          class C
                            def method_name
                       3. Instance method definition in module I. Individual object extended by M
                          module M                             II. Instance of class that mixes in M
                            def method_name
                       4. Singleton method(including class     obj
                          methods)
                          def obj.method_name


4,定义与Ruby内建类重名的类的时候,如定义Violin::String,我们要在Violin里调用Ruby内建的String类时,使用::String

5,Ruby三种作用域,public/protected/private,默认为public
private方法不能使用explicit receiver,只能被implicit receiver self调用,如可以method_name,而不能obj.method_name
protected方法的调用保证了self的class和被调用的另一个对象的class相同

6,top-level方法为Kernel模块的private instance methods

你可能感兴趣的:(C++,c,读书,Ruby,Rails)