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 
  • 相关阅读:
    Python性能鸡汤
    postgreSQL设置自增长字段并插入值
    DBSCAN算法的Java,C++,Python实现
    查看进程及端口使用情况
    软件工程中的各种图
    程序员技术练级攻略[转]
    CSS中 opacity的设置影响了index(层数)的改变
    页面预加载loading动画
    JS 判断用户使用的设备类型
    图片懒加载——介绍
  • 原文地址:https://www.cnblogs.com/wangyuyu/p/3341388.html
Copyright © 2011-2022 走看看