Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Elixir have a variable which holds the name of the current file (ala Ruby’s __FILE__)?

Tags:

elixir

How in Elixir can I specify the current file being compiled? In Ruby, I can use the __FILE__ variable. Is there an equivalent in Elixir?

Here is my script:

IO.puts “#{__FILE__}”

Here is the output:

** (CompileError) ModulesAndFunctions-7.exs:3: undefined function __FILE__/0
    (elixir) expanding macro: Kernel.to_string/1
    ModulesAndFunctions-7.exs:3: (file)
like image 807
Michael Bishop Avatar asked Mar 13 '23 04:03

Michael Bishop


1 Answers

You can simply use __ENV__.file

like image 93
NoDisplayName Avatar answered Apr 27 '23 20:04

NoDisplayName