在Ruby中读取一个文件有两种方法:require和load。这两者的区别在于:
load “file.rb”
load “file.rb”
这段代码会把file.rb读取两边。而如果是:
require “file.rb”
require “file.rb”
这样子的代码,file.rb只是在第一次的时候被载入,接下来那次其实是没有作用的。所以如果遇到一些程序的值是被修改过的,我们就需要用到load来保证ruby读到的是最新的内容。
可是我的问题出现在第二次用load读取文件的时候。我先建立一个文件名为reqdemo.rb的文件:
puts “This is the first (master) program file”
require ‘requiree.rb’
puts “And back again to the first file.”
先让ruby输出一段字符”This is the first (master) program file”,然后在读取reuiree.rb的文件内容,最后再输出一段字符”And back again to the first file.”。接着我们创建requiree.rb文件,输入如下代码:
puts “>This is the second file, which was ‘required’ by the first.”
所以如果运行reqdemo.rb,我们能得到如下结果:
c:\ruby4rails>reqdemo.rb
This is the first (master) program file.
>This is the second file, which was ‘required’ by the first.
And back again to the first file.
最后我们建立一个loaddemo.rb并输入如下代码:
load “reqdemo.rb”
load “reqdemo.rb”
把reqdemo.rb读取两遍。执行loaddemo.rb应该得到重复的两个reqdemo.rb的结果。可是现在我得到的结果是:
c:\ruby4rails>loaddemo.rb
This is the first (master) program file.
>This is the second file, which was ‘required’ by the first.
And back again to the first file
This is the first (master) program file.
And back again to the first file
在第二次load reqdemo.rb时,requiree.rb没有被读取…这是为什么?我到现在还没有想通…
在生活帮上看到Productivity501的Mark列举的最浪费自己的时间的5种情况。
- 电视
- 交通
- 上网
- 劳累
- 没有足够的技能
他们自己列举的是:
- 上网
- 玩游戏
- 睡觉
- 写blog
- 看电影
那么对我来说最浪费时间的5件事是什么呢?我想应该是下列5件事:
1.上网
2.看电影
3.写Blog
4.交通
5.睡觉 – -b(这个也算浪费时间吗)
天堂再好,不及你在我身边的美丽.今天在”心灵花园”的一期节目中听到的一句话.一刹那就像一枚子弹击中胸膛,心底那个最柔软的地方又被轻轻地触碰了一下.
“天堂再好,不及你在我身边的美丽”
Technorati Tags: Love, Haven, You, beside
powered by performancing firefox