Ruby: How to call function before it is defined?

后端 未结 5 1958
星月不相逢
星月不相逢 2021-01-11 10:08

In my seeds.rb file I would like to have the following structure:

# begin of variables initialization
groups = ...
# end of variables initializa         


        
5条回答
  •  遥遥无期
    2021-01-11 11:07

    Wrap your initial calls in a function and call that function at the end:

    # begin of variables initialization
    groups = ...
    # end of variables initialization
    
    def to_be_run_later
      check_data
      save_data_in_database
    end
    
    # functions go here
    def check_data
      ...
    end
    
    def save_data_in_database
      ...
    end
    
    to_be_run_later
    

提交回复
热议问题