Scope
首先补充一下ruby 中的import(和java对比),
require_relative
variables
对于method来说,outside variables的作用域仅限于外部,内部也是,互不干扰。
对于block来说,外部变量的作用域覆盖内部
CONSTANCE
可以在method内部使用和修改外部常量,但是修改只作用于内部,不影响外部的值。
Access Control
两种将method设置为private的方法
1.
private
def test1
..
end
2.
def test1
..
end
private:test1
private 的method除了使用setter不可使用self.method