Class: Fried::Test::PrependToLoadPath
- Inherits:
-
Object
- Object
- Fried::Test::PrependToLoadPath
- Defined in:
- lib/fried/test/prepend_to_load_path.rb
Overview
Unshifts the path to $LOAD_PATH unless already existing
Instance Attribute Summary collapse
-
#load_path ⇒ Object
Returns the value of attribute load_path.
Class Method Summary collapse
Instance Method Summary collapse
-
#call(path) ⇒ Boolean
true if path was added, false if already present.
-
#initialize ⇒ PrependToLoadPath
constructor
A new instance of PrependToLoadPath.
Constructor Details
#initialize ⇒ PrependToLoadPath
Returns a new instance of PrependToLoadPath.
8 9 10 |
# File 'lib/fried/test/prepend_to_load_path.rb', line 8 def initialize @load_path = [] end |
Instance Attribute Details
#load_path ⇒ Object
Returns the value of attribute load_path.
6 7 8 |
# File 'lib/fried/test/prepend_to_load_path.rb', line 6 def load_path @load_path end |
Class Method Details
.build ⇒ Object
12 13 14 15 16 |
# File 'lib/fried/test/prepend_to_load_path.rb', line 12 def self.build new.tap do |instance| instance.load_path = $LOAD_PATH end end |
.call ⇒ Object
29 30 31 32 |
# File 'lib/fried/test/prepend_to_load_path.rb', line 29 def self.call instance = build instance.() end |
Instance Method Details
#call(path) ⇒ Boolean
Returns true if path was added, false if already present.
20 21 22 23 24 25 26 27 |
# File 'lib/fried/test/prepend_to_load_path.rb', line 20 def call(path) text_path = path.to_s has_path = load_path.include?(text_path) load_path.unshift(text_path) unless has_path !has_path end |