Try to you explain to yourself step by step what you are doing and why. Then you would discover that you are doing something weird.
In Ruby, strings are mutable. The
<< operator is short for append, so the receiver string will be modified so it has the argument string at the end.
When repeatedly loading your file your are doing the following:
- You declare a constant (or redeclare it, causing a warning)
PLUGIN_ROOT, which is a folder path like
- Then you append
\shadows.rb, so PLUGIN_ROOT now looks like:
- Then you check whether this string is contained in the already registered file paths (which is false).
In the condition block, you have to register that this file path (or what ever string you use) has been loaded:
PLUGIN_ROOT = File.expand_path(File.dirname(__FILE__)) # normalize the path
shadows_file = File.join(PLUGIN_ROOT, "shadows.rb")
# UI stuff
You can also just use
__FILE__ to refer to the file that the Ruby interpreter currently reads (
(By the way, if you use
/ as file path separator you don’t have to escape and it is internally preferred in Ruby.)