Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
zhouguangming
@zgm
高级会员
第 115 位会员 / 2011-11-17

ctrip.com
上海
14 篇帖子 / 1356 条回帖
37 关注者
0 正在关注
0 收藏
GitHub Public Repos
  • OpenHands 0

    🙌 OpenHands: Code Less, Make More

  • spec 0

    CloudEvents Specification

  • rails 0

    Ruby on Rails

More on GitHub
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • 卖个萌 :) ,Show 一下大家的小孩 at 2013年04月12日

    #21 楼 @yedingding 时候时候上 Teahour.fm 啊。

  • [上海] Rails Web 开发工程师 (已結束) at 2013年04月12日

    #18 楼 @lgn21st 从心里~~~ 😄

  • 请问有没有专门介绍 Gem 测试的文章的? at 2013年04月12日

    #2 楼 @hz_qiuyuanxin 看来是 rails 迷惑了你啊。你可以去 github 上面找一些相对简单的 Gem 看看他们的测试就可以了。

  • 实在忍不住了 at 2013年04月12日

    #6 楼 @Saito magic mouse 还用解释么。 露珠在不经意间就炫了这么多东西,然后深藏功与名。

  • simple_form_for 报错 undefined method `encoding' for nil:NilClass at 2013年04月12日

    http://ruby-china.org/topics/6492 不完全一样,可以参考。 你这个问题神马线索都没有,没办法解决。

  • 请问有没有专门介绍 Gem 测试的文章的? at 2013年04月12日

    先学个测试工具你就知道了。

  • 实在忍不住了 at 2013年04月12日

    RMBP 也很亮啊。

  • 卖个萌 :) ,Show 一下大家的小孩 at 2013年04月12日

  • rails middleware 太多是否会有性能问题? at 2013年04月11日

    #14 楼 @Rei 用了 Archlinux 之后我就更喜欢做加法了。

  • rails middleware 太多是否会有性能问题? at 2013年04月11日

    还是做加法好啊。

  • 有什么 gem 可以显示 rails 信息的? at 2013年04月11日

    @iBachue @kenshin54 @linjunhalida 打开不就得了

  • 简单吐槽 at 2013年04月11日

    不会出神马不测了吧。~

  • 关于 "undefined method `type' for nil:NilClass" at 2013年04月11日

    你也没提供什么线索。

  • 一个元编程的代码跟踪, 求大神指教其中的调用顺序, 有点摸不着头绪了 at 2013年04月10日

    打印结果

    1:
    One called with Hello 
    2:
    ##
    Example
    one
    *****
    3.1:
    @@@
    two
    
    $$$$
    3.2:
    ##
    Example
    two
    *****
    3.3:
    @@@
    two
    true
    $$$$
    4:
    ==> calling one with ["GoodBye"]
    One called with GoodBye
    <== one returned nil
    5:
    ==> calling two with [4, 5]
    <== two returned 9
    9
    

    分析

    1.
    ex1.one("Hello")  => # 打印 1
    2.
    include TraceCalls =>
    self.included(klass) => 
    wrap(klass, existing_method) => 
    def self.wrap(klass, method)
      # 打印 2
      puts "###{}"
      puts klass
      puts method
      puts "*****"
      # 结束打印 2
      klass.instance_eval do
         method_object = instance_method(method)
         define_method(method) do |*args, &block|
            puts "==> calling #{method} with #{args.inspect}"
            result = method_object.bind(self).call(*args, &block)
            puts "<== #{method} returned #{result.inspect}"
            result
         end
      end
    end
    
    3.
    def two(arg1, arg2)
       arg1 + arg2
    end
    =>
    def klass.method_added(method)
        # 打印 3.1
        puts "@@@"
        puts method
        puts @trace_calls_internal
        puts "$$$$"
        # 结束打印 3.1
        unless @trace_calls_internal
           @trace_calls_internal = true
           TraceCalls.wrap(self, method) =>(
           def self.wrap(klass, method)
              # 打印 3.2
              puts "###{}"
              puts klass
              puts method
              puts "*****"
              # 结束打印 3.2
              klass.instance_eval do
                 method_object = instance_method(method)
                 define_method(method) do |*args, &block|
                    puts "==> calling #{method} with #{args.inspect}"
                    result = method_object.bind(self).call(*args, &block) 
                    puts "<== #{method} returned #{result.inspect}"
                    result
                end =>(
                def klass.method_added(method)
                  # 打印 3.3
                  puts "@@@"
                  puts method
                  puts @trace_calls_internal
                  puts "$$$$"
                  # 结束打印 3.3
                  unless @trace_calls_internal
                    @trace_calls_internal = true
                    TraceCalls.wrap(self, method)
                    @trace_calls_internal = false
                end
              end
              )
            end
          end
           ) 
           @trace_calls_internal = false
        end
        # 结束打印 3
    end
    
    4. 
    ex1.one("GoodBye") => 
    
    define_method(method) do |*args, &block|
        #  打印 4
        puts "==> calling #{method} with #{args.inspect}"
        result = method_object.bind(self).call(*args, &block)
        puts "<== #{method} returned #{result.inspect}"
        # 结束打印4
        result
    end
    
    5. puts ex1.two(4, 5) =>
    
    define_method(method) do |*args, &block|
       # 打印 5
       puts "==> calling #{method} with #{args.inspect}"
       result = method_object.bind(self).call(*args, &block)
       puts "<== #{method} returned #{result.inspect}"
       # 结束 打印 5
       esult
    end
    

    参考资料

    1. Module.included http://www.ruby-doc.org/core-2.0/Module.html#method-i-included
    2. Module.method_added http://www.ruby-doc.org/core-2.0/Module.html#method-i-method_added
    3. Module.instance_methods http://www.ruby-doc.org/core-2.0/Module.html#method-i-instance_methods
    4. BaseObject.instance_eval http://ruby-doc.org/core-2.0/BasicObject.html#method-i-instance_eval
    5. BaseObject.define_method http://www.ruby-doc.org/core-2.0/BasicObject.html#method-i-instance_eval

    好累,感觉不会再爱了。

  • 数组排序求简单实现 at 2013年04月10日

    @kenshin54 @Grant 大神的代码在哪啊

  • 吐槽一下注释 at 2013年04月09日

    我觉得注释还是有必要的。 尤其是那些关于具体 业务 的代码,靠逻辑根本解释不清楚,这时候最好有注释,最起码也要标明当时写的文档的位置吧,要不然下个程序员脑袋想炸也不知道它们为什么会这样。 亲身经历。

  • ruby method_missing 重写报错, 望大牛给予帮助 at 2013年04月09日

    这种排版我基本上不会看。

  • 我上线并同时开源的第一个网站,欢迎拍砖 at 2013年04月08日

    话说 6 级 410 分为什么放简历里?

  • 我上线并同时开源的第一个网站,欢迎拍砖 at 2013年04月08日

    我个人觉得很不错。加油。

  • Teahour.fm 第 11 期发布 -- 采访 Rei at 2013年04月08日

    偶像!

  • ruby china 是怎么做手机浏览器的兼容的? at 2013年04月07日

    可能是 bootstrap 吧

  • Ruby China 帖子过万啦 at 2013年04月07日

    两年大家都有什么改变呢?

  • Ruby China iPhone App 上架了 at 2013年04月07日

    不错!

  • 上一页
  • 1
  • 2
  • …
  • 32
  • 33
  • 34
  • 35
  • 36
  • …
  • 44
  • 45
  • 下一页
关于 / RubyConf / Ruby 镜像 / RubyGems 镜像 / 活跃会员 / 组织 / API / 贡献者
由众多爱好者共同维护的 Ruby 中文社区,本站使用 Homeland 构建,并采用 Docker 部署。
服务器由 赞助 CDN 由 赞助
iOS 客户端 / Android 客户端 简体中文 / English