ruby类变量在development模式失效
分页中用到类变量,主要是用来标记“页码输入框”的id 如果一个页面有几个分页,“页码输入框”的id要是不同的才能分清是哪个要分页。使用类变量就是为了达到这个目的,让所有的对象实例共用一个变量,不必每次重新初始化变量。 类变量使用代码示例 1 require 'ruby-debug'
2 debugger
3 class Myclassvar
4 @@a=1
5 puts 1111111111111111111111
6 puts @@a
7
8 def testa
9 @@a=@@a+5
10 end
11 def testb
12 @@a=@@a+3
13 end
14 end
15
16 class Reclassvar < Myclassvar
17 def testa
18 @@a+=10
19 end
20 end
21
22 obj=Myclassvar.new
23 puts obj.testa
24 puts obj.testb
25 obj2=Myclassvar.new
26 puts obj2.testb
27 obj3=Reclassvar.new
28 puts obj3.testa
执行顺序是 3=>4=>5=>6=>8=>11=>16=>17=>22=>23=>9=>24=>12=>25=>26=>12……
本地测试类变量完全符合预想,但是项目中的分页用到的类变量却是每次都要初始化,一度郁闷中。结果是因为Rails开在development模式时配置中有config.cache_classes = false,所以我们每次不用重启服务就可以查看更新代码后的运行结果。而服务器上的程序是开启在production模式,其中config.cache_classes = true。这就是为什么类变量在development模式会失效,每次重新载入某个类时,它的所有类变量都会再次初始化。
相关文档:
Beginning Ruby from Novice To Perfessional
Head First Rails
Agile Web Development with Rails 3rd Edition(new)
Agile Web Development with Rails 3rd Edition
Agile Web Development with Rails 3rd Editio ......
When I try the command "gem install thrift" with Ruby 1.9.1, I got a compilation error with something related to a C function "strlcpy()".
Then I searched the web. It seems I am not alone and the community know it.
However I do not want to wait for official update, I want to ......
历史背景[1]
诞生于1993年2月24日的Ruby(红宝石),由日本人松本行弘(Yuki Matsumoto)于1994年12月发布。 Ruby 作为一种纯面向对象的脚本程序设计语言,吸收了Smalltalk和Perl两种程序语言的特性。
Ruby理念[2]
1.首先考虑的是,减少编程时不必要的琐碎时间,令编写程序的人高兴;
2.其次是良好的界面设计;
3.强 ......
转 Adding Sound to Your Ruby Apps
Have you ever thought about including sounds in your Ruby application? Used sparingly, sound may enhance your applications by adding audio cues or a custom touch. You could, for example, play a beep or chime that announces the completion of a lengthy process. Per ......
转自 http://www.javaeye.com/topic/57474
Windows平台的ruby IDE 点评
在MacOS平台几乎没有什么争议性,大家都用TextMate。但是Windows平台可供选择和使用的IDE很多,却各有各的长处和短处。基于我用过的所有ruby IDE点评一下。windows平台的RoR IDE主要分为两类:一类是重量级的全功能IDE,例如Eclipse,Netbeans ......