首先,要明白这几个ruby的原理1、默认(包括你所用的定义方法)在顶层定义的都是private的实例方法2、private方法是不允许指明接收者的,其接收者只能是隐含的selfdef x11puts "in x11"enddef x11=(t) puts tend x11self.x11="ddd"当前定义了两个方法,都是private的,可以puts self.private_methods.sort 看到那为什么 x11可执行,self.x11不能执行了? 上面已有解释,调用对象所属类的实例方法是不能加self的,因为,ruby中的private很微秒,它与java等都不同。它 ...
运行时提示已active0.4.5.不能active1.0.0,那直接删除0.4.5的gem就行了。
2008-06-17

Ruby中闭包与block

关键字: 闭包
转道友Blog中的一小段code说明ruby中的闭包 procs = [] (1..3).each do |i| procs << lambda { puts i } end procs.each { |p| p.call } # Output: # 1 # 2 # 3 ############################################### procs = [] for j in (1..3) do procs << la ...
  def trc_utf8(text, length = 40, t_string = "...")        l=0        char_array=text.unpack("U*")        char_array.each_with_index do |c,i|        ...
 TCMalloc(Thread-Caching Malloc)是google开发的开源工具──“google-perftools”中的成员。与标准的glibc库的malloc相比,TCMalloc在内存的分配上效率和速度要高得多,可以在很大程度上提高MySQL服务器在高并发情况下的性能,降低系统负载。  TCMalloc的实现原理和测试报告请见一篇文章:《TCMalloc:线程缓存的Malloc》  为MySQL添加TCMalloc库的安装步骤(Linux环境):  1、64位操作系统请先安装libunwind库,32位操作系统不要安装。libunwind库为基于64 ...
  • 09:15
  • 浏览 (47)
  • 评论 (0)
require 'net/http'require 'uri'module Net  class HTTP    def HTTP.get_with_headers(uri,headers=nil)      uri=URI.parse(uri) if uri.respond_to? :to_str      start(uri.host,uri.port) do |http|      &nbs ...
用ruby写个网页抓取的小东东,遇到问题: 环境:ubuntu8.04+netbeans6.1+ruby1.8.6 在ruby中使用Net::HTTP.get_response抓取一个GB2312编码的网页后转换成utf8全是乱码,主要代码部分如下 resp=Net::HTTP.get_response(URL,URI) body=resp.body[0,resp.size-1] r=Iconv.iconv("UTF-8//IGNORE","GB2312//IGNORE",body)  接下来我要使用r中的内容 但是发现里面的内容全是乱码,直接写入数据库写不进去,提 ...
== Installation<tt>./script/plugin install http://code.dunae.ca/acts_as_slugable</tt>== Usage examplesIn your target table, add a column to hold the URL slug.=== With scope  class Page < ActiveRecord::Base    acts_as_slugable :source_column => :title, :target_co ...
http://www.codyfauser.com/2008/1/17/paypal-express-payments-with-activemerchant
中国省,市,县(区)三级数据信息,已转换成mysql的dump文件