Ruby: How to call function before it is defined?

后端 未结 5 1967
星月不相逢
星月不相逢 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:06

    You could use END (upper case, not lower case)

    END {
      # begin of variables initialization
      groups = ...
      # end of variables initialization
      check_data
      save_data_in_database
    }
    

    but that'd be a bit of a hack.

    Basically, END code is run after all other code is run.

    Edit: There's also Kernel#at_exit, (rdoc link)

提交回复
热议问题