[Ruby笔记]25.local scope 本地作用域
2016-06-28 20:29
435 查看
code
# file : nest2.rb class A x = 'A' module M x = 'M' class B x = 'B' def show_x x = 'X' puts x end puts x end puts x end puts x end puts "a = A.new" a = A.new puts "b = A::M::B.new" b = A::M::B.new puts "b.show_x" b.show_x
output
仔细看输出,发现a = A.new以及
b = A::M::B.new的执行其实并没有带来任何输出;
在
show_x语句执行之后,才会打印出X;
而
B M A是
ruby nest2.rb命令行运行之后就直接输出了;
PS C:\Users\Administrator\RubyCode> ruby nest2.rb B M A a = A.new b = A::M::B.new b.show_x X
reference
《The Well-Grounded Rubyist, Second Edition》(https://www.manning.com/books/the-well-grounded-rubyist-second-edition)
5.2.2. Local scope
ねむ… ∧_∧ ゚(´д⊂ヽ/⌒ヽ ./ ノ ) ⊂_/⌒ ,, ) (ニニニニニニニニ) http://emoji.vis.ne.jp/nemui44.htm[/code]
相关文章推荐
- Android Native 绘图方法
- 红宝石(Ruby)史话
- Ruby简明教程之循环语句介绍
- ruby 一些简单的例子
- Ruby on Rails在Ping ++ 平台实现支付
- Ruby 之 class 中的 private、 protected、public
- Ruby中操作文件的方法介绍
- 详解Ruby中的单件方法和单件类
- Ruby中的集合编写指南
- CentOS 6.3下编译安装Ruby 2.0笔记
- Ruby基本的环境变量设置以及常用解释器命令介绍
- 详解Ruby中的代码块及其参数传递
- Ruby编程中关于中断和返回的用法教程
- Ruby中的异常处理代码编写示例
- Ruby程序中发送基于HTTP协议的请求的简单示例
- Ruby中的变量学习总结
- 几个加速Ruby on Rails的编程技巧
- Ruby配置rspec和RestClient来检测服务器
- 分析Cache 在 Ruby China 里面的应用情况