Last active
          August 29, 2015 13:57 
        
      - 
      
- 
        Save hayeah/9380257 to your computer and use it in GitHub Desktop. 
    callback chain ordering
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | require "active_support/callbacks" | |
| class Foo | |
| include ActiveSupport::Callbacks | |
| define_callbacks :foo | |
| set_callback :foo, :around, :around_1 | |
| set_callback :foo, :before, :before_1 | |
| set_callback :foo, :after, :after_1 | |
| def after_1 | |
| puts "after_1" | |
| end | |
| def before_1 | |
| puts "before_1" | |
| end | |
| def before_2 | |
| puts "before_2" | |
| end | |
| def around_1 | |
| puts "around_1 top" | |
| yield | |
| puts "around_1 bottom" | |
| end | |
| end | |
| foo = Foo.new | |
| foo.run_callbacks :foo do | |
| puts "in run callbacks" | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
顺序是固定的,没错。我原本以为顺序应该是