How to cancel evaluating a required Ruby file? (a.k.a. top-level return)

后端 未结 4 974
不知归路
不知归路 2021-01-17 19:14

file1 requires file2, and I want to be able to cancel evaluating file2 under certain conditions without exiting the whole process.

4条回答
  •  旧巷少年郎
    2021-01-17 19:26

    Is using a method possible ? It will still parse the method but won't get executed. Something like :

    #file1.rb
      puts "In file 1"
      require 'file2'
      puts "Back in file 1"
      a_method
    
    #file2.rb
      puts "In file 2"
      # <= A
    
      def a_method
        puts "Still in file 2"
      end
    

提交回复
热议问题