public
Created

`self.inspect == 'main'` is no substitute for `__FILE__ == $0`

  • Download Gist
main-tester-caller.rb
Ruby
1 2
require './main-tester'
puts "done in caller"
main-tester.rb
Ruby
1 2 3 4 5
if self.inspect == 'main'
puts "I'm main"
else
puts "I'm a library"
end
output.txt
1 2 3 4 5
$ ruby main-tester.rb
I'm main
$ ruby main-tester-caller.rb
I'm main
done in caller

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.