I am experimenting with ruby (2.4.1p111) and with the load method and it does have some strange behavior:
I have two files:
mytest.rb:
class MyClass
def self.greet(param)
puts "Got called: #{param}"
end
greet 'Called locally'
load "./testld.rb"
end
and the loaded file:
testld.rb:
greet 'Called by load'
I understood from documentation that the loaded code from testld.rb and the method call right in the MyClass should behave the same. Instead, I am getting:
-bash-4.2$ ruby mytest.rb
Got called: Called locally
/Blacksmith/RB/testld.rb:1:in `<top (required)>': undefined method `greet'
for main:Object (NoMethodError)
from mytest.rb:9:in `load'
from mytest.rb:9:in `<class:MyClass>'
from mytest.rb:1:in `<main>'
Any idea what I do wrong?
MyClassintestld.rb, it will be called as if it was. If it was not, it will not, no matter where you load it.eval File.read('testld.rb')butloaddoesn't work that way.loadto perform a copy-paste. xd