zoukankan      html  css  js  c++  java
  • 关于around_filter 的调用


     
    Java代码  收藏代码
    1. def call_filter(chain, index)  
    2.   
    3.         return (performed? || perform_action_without_filters) if index >= chain.size  
    4.   
    5.         filter = chain[index]  
    6.   
    7.         return call_filter(chain, index.next) if self.class.filter_excluded_from_action?(filter,action_name)  
    8.   
    9.   
    10.   
    11.         halted = false  
    12.   
    13.         filter.call(self) do  
    14.   
    15.           halted = call_filter(chain, index.next)  
    16.   
    17.         end  
    18.   
    19.         halt_filter_chain(filter.filter, :no_yield) if halted == false unless @before_filter_chain_aborted  
    20.   
    21.         halted  
    22.   
    23.       end  


        在control 的 around_filter的函数和代码块中,总是会需要yield, 那么这个yield 执行的参数是什么呢,就是上面的 call_filter(chain,index.next). 通过这几行代码,就可以解释如下代码的调用结果
    "---------test_one-------------"
    "-----------test_two-----------"
    "--------end of test_two-------"
    "---------end of test_one------"

    Java代码  收藏代码
      1. around_filter :test_one  
      2.   around_filter :test_two  
      3.   
      4.   def test_one  
      5.     p "---------test_one-------------"  
      6.     yield  
      7.     p "---------end of test_one------"  
      8.   end  
      9.   
      10.   def test_two  
      11.     p "-----------test_two-----------"  
      12.     yield  
      13.     p "--------end of test_two-------"  
      14.   end 
  • 相关阅读:
    poj-3580-SuperMemo-splay
    JS 添加到事件的多个对象
    1.9 效率高,安排约会
    我展示了视频采集前端vfe和camera,decode等交互驱动的体系结构
    2013年7月27日杂记
    深入JS系列学习4
    深入JS系列学习3
    深入JS系列学习2
    高质量JavaScript代码书写基本要点学习
    给硬件复兴把脉 硬件创新最有机会的十个方向
  • 原文地址:https://www.cnblogs.com/wangyuyu/p/3341388.html
Copyright © 2011-2022 走看看