繁体   English   中英

在红宝石中,我怎么知道回忆方法在做什么?

[英]In ruby, how do I know what a memoist method is doing?

我现在正在基于health-data-standards库( https://github.com/projectcypress/health-data-standards.git )进行开发。 在文件lib / health-data-standards / export / helper / scooped_view_helper.rb( https://github.com/projectcypress/health-data-standards/blob/master/lib/health-data-standards/export/helper /scooped_view_helper.rb )第90行,将调用Patient.entries_for_oid 但是该方法未定义。

在Pry环境下,我尝试“编辑Patient.entries_for_oid”。 编辑器在第166行打开memoist / lib / memoist.rb( https://github.com/matthewrudy/memoist/blob/master/lib/memoist.rb )。在这里,我看到了以下代码:

          module_eval <<-EOS, __FILE__, __LINE__ + 1
        def #{method_name}(*args)
          reload = Memoist.extract_reload!(method(#{unmemoized_method.inspect}), args)

          skip_cache = reload || !(instance_variable_defined?(#{memoized_ivar.inspect}) && #{memoized_ivar} && #{memoized_ivar}.has_key?(args))
          set_cache = skip_cache && !frozen?

          if skip_cache
            value = #{unmemoized_method}(*args)
          else
            value = #{memoized_ivar}[args]
          end

          if set_cache
            #{memoized_ivar} ||= {}
            #{memoized_ivar}[args] = value
          end

          value
        end
      EOS
    end

但这没有意义,耐心.entries_for_oid到底是做什么的。

有人知道吗?

谢谢

该方法在Record模型类上定义 此类的实例将传递到帮助器中的entries_for_data_criteria方法。

您不会简单地看到实际的方法源,因为作者选择使用Memoist宝石,该宝石可用于包装任意方法以扩展其行为(在这种情况下,是缓存,或更准确地说是记忆)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM