Ruby China
  • Topics
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • Sign Up
  • Sign In
李平
@hiveer
Member
NO. 6829 / 2013-04-23

极狐(GitLab)
成都
69 Topics / 390 Replies
40 Followers
4 Following
38 Favorites
Reward
GitHub Public Repos
  • custom_log_generator 2

    Generate custom Rails logger

  • slider_button 2

    An example of how to build a slider button

  • War3-2V2-Homepage 1

    魔兽与人生-魔兽22争霸赛主页

  • vim-settings 0

    *all my experience about vim

  • railsbp_in_browser 0

    A tool based on 'rails_best_practices' which is to generate readable code analysis page in browser

  • casdoor_opencsg 0

    An open-source UI-first Identity and Access Management (IAM) / Single-Sign-On (SSO) platform with...

  • hiveer-resume 0

    Online Resume

  • amap-app 0

    Play with AMap features

  • SimpleWhaleDemo 0

    a dockerized application

More on GitHub
  • Overview
  • Topics
  • Replies
  • Favorites
  • Following
  • Followers
  • 想做一个语音群聊,跪求指点 at September 02, 2014

    @MrPasserby @jimrokliu 基于网页,多人语音。

  • Rails 4.2 新增后端任务框架 - Active Job at August 29, 2014

    这个不是 4.1 就有吗?

  • [全职 Remote] 秒视 CatchChat 招 Rubyist,开发大规模实时短视频 IM 后端 (上线一周拿到 A 轮) at August 28, 2014

    #53 楼 @Ryan 啊!要读研(博),有魄力

  • [全职 Remote] 秒视 CatchChat 招 Rubyist,开发大规模实时短视频 IM 后端 (上线一周拿到 A 轮) at August 28, 2014

    #51 楼 @Ryan 你的玩具是我们的饭碗!

  • Hash string key? or symbol key? at August 28, 2014

    #3 楼 @outman 对头

  • Hash string key? or symbol key? at August 28, 2014

    #1 楼 @huacnlee 嗯,对。如果个人能统一风格的话,其实这个就没有多大必要。不过,很多时候都是 coworking,所以实际开发也不好避免。对此,Rails 还有一个扩展方法Hash#with_indifferent_access,可以达到同样的效果,这个在处理 Hash 参数的时候还是挺有用的。

  • HTTParty 的源码 at August 19, 2014

    @kepaning 从代码上看是没有明显的调用,不过可以起到防患未然的作用

  • HTTParty 的源码 at August 19, 2014

    @kepaning 我上面只是举个例子,test代表了在ClassMethods中定义的实例方法

  • HTTParty 的源码 at August 18, 2014

    @outman @kepaning 仔细研究了下,发现源码没有问题 第一个 extend AllowedFormatsDeprecation是为了处理 下面这种情况的 HTTParty::AllowedFormats 的常量调用

    第二个extend AllowedFormatsDeprecation是为了处理在ClassMethods里面的方法的常量调用

    module ClassMethods
      def test
        AllowedFormats
      end
    end
    

    *为了更好的理解上面的解释,还需要特别注意我们在include和extend module的时候,base的 mixing 方法实际上只是对应module方法的一个引用。

    pry(main)> ls Test
    Out::ClassMethods#methods: test_const
    
    pry(main)> ls Mixing
    Mix#methods: b
    
    

    这也是为什么需要第二个 extend AllowedFormatsDeprecation的原因

  • HTTParty 的源码 at August 18, 2014

    #4 楼 @kepaning 除了在include HTTParty的时候会有base.extend ClassMethods,还有什么时候我们回去调用HTTParty::ClassMethods::XXXX

  • HTTParty 的源码 at August 18, 2014

    @outman 我已经在 github 上提了一个 issue,有回馈这边会更新

  • [成都] 活跃网络 Ruby 高级开发工程师 12K-25K at August 15, 2014

    成都的 ruby 不少呀,怎么不来顶起

  • [香港] 招聘 Ruby on Rails/Javascript 工程师 15k-30k/月 at August 14, 2014

    可以 remote 吗

  • Rails 技巧之 tap & try at August 06, 2014

    嗯,好东西!

  • [成都]2014年8月23日,Ruby 社区聚会! at August 05, 2014

    赞!

  • 关于 Rails 的缓存(ActiveSupport::Cache::Strategy::LocalCache 该怎么用?) at July 28, 2014

    自己研究了下,下面是一些成果

    ActiveSupport::Cache::DalliStore#with_local_cache
    
    def with_local_cache
      use_temporary_local_cache(LocalStore.new) { yield }
    end
    
    def use_temporary_local_cache(temporary_cache)
      save_cache = LocalCacheRegistry.cache_for(local_cache_key)
      begin
        LocalCacheRegistry.set_cache_for(local_cache_key, temporary_cache)
        yield
      ensure
        LocalCacheRegistry.set_cache_for(local_cache_key, save_cache)
      end
    end
    
    def write(name, value, options=nil)
      options ||= {}
      name = expanded_key name
    
      instrument(:write, name, options) do |payload|
        with do |connection|
          options = options.merge(:connection => connection)
          write_entry(name, value, options)
        end
      end
    end
    
    def write_entry(key, entry, options) # :nodoc:
      local_cache.write_entry(key, entry, options) if local_cache
      super
    end
    

    然后解释下上面的代码,如果我们把平时使用缓存的代码,比如 Rails.cache.write('name', 'key') 作为方法 with_local_cache 的参数,那么最终会产生一个结果,那就是会有两个地方缓存了这对 key,value。一个地方就是 LocalCache,另一个地方就是我们指定的 Rails 缓存。

    有了以上的这些理解,我们再来看看官方的解释

    Caches that implement LocalCache will be backed by an in-memory cache for the

    duration of a block. Repeated calls to the cache for the same key will hit the

    in-memory cache for faster access.

    是不是有一种恍然大悟的感觉!

    不得不感叹!不是别人的代码太晦涩,只是因为我们看不懂注释!

  • 关于 Rails 的缓存(ActiveSupport::Cache::Strategy::LocalCache 该怎么用?) at July 28, 2014

    自己顶一下!

  • [成都][高新区] 瑞小博科技有限公司招聘 web 后端开发工程师一名(高薪好待遇) at July 28, 2014

    那就再顶一个!

  • Rails 3.2.13 使用 Spork + Guard + RSpec + Capybara at July 25, 2014

    经典好帖!

  • 已招 at July 24, 2014

    看到了 remote,果断进来先赞一个!

  • 推荐 Ruby & Rails 内部实现文集 at July 04, 2014

    嗯,很赞

  • 怎么理解 extend at July 02, 2014

    @jun1st 谢谢,这个例子很好,一下就明白了它的用处 @liy_j 谢谢您的详细解答,对于“初始化模块中的某些属性(很少用),能不能给个例子呢?”

  • 怎么理解 extend at June 30, 2014

    @liy_j 如果说模块里面的实例方法是用来给 include 或者是 extend 他的类做扩展用,那么模块的类方法又有什么实际的用处呢?

  • Sidekiq 精通 36 分钟 at June 20, 2014

    跟 resque 如此相似,希望 LZ 能将他们做个对比,期待后续!

  • Prev
  • 1
  • 2
  • …
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • Next
关于 / RubyConf / Ruby 镜像 / RubyGems 镜像 / 活跃会员 / 组织 / API / 贡献者
由众多爱好者共同维护的 Ruby 中文社区,本站使用 Homeland 构建,并采用 Docker 部署。
服务器由 赞助 CDN 由 赞助
iOS 客户端 / Android 客户端 简体中文 / English