Ruby: How to call function before it is defined?

后端 未结 5 1970
星月不相逢
星月不相逢 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 10:56

    Andrew Grimm mentions END; there's also BEGIN

    foo "hello"
    
    
    BEGIN {
    def foo (n)
      puts n
    end}
    

    You can't use this to initialize variables because the {} defines a local variable scope.

提交回复
热议问题