Skip to content

Instantly share code, notes, and snippets.

@murajun1978
Created October 10, 2014 15:15
Show Gist options
  • Save murajun1978/f1f40ad1bbf7c6bd3b37 to your computer and use it in GitHub Desktop.
Save murajun1978/f1f40ad1bbf7c6bd3b37 to your computer and use it in GitHub Desktop.
__FILE__と$0の違い
require_relative 'require_file'
include RequireFile
$0 # => "current_file.rb"
__FILE__ # => "current_file.rb"
__LINE__ # => 6
File.expand_path(__FILE__) # => "path/to/current_file.rb"
stdout_method
# $0 # => "current_file.rb"
# __FILE__ # => "path/to/require_file.rb"
# __LINE__ # => 5
# File.expand_path(__FILE__) # => "path/to/require_file.rb"
module RequireFile
def stdout_method
p $0
p __FILE__
p __LINE__
p File.expand_path(__FILE__)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment