Is it possible to access instance variable defined in a controller by a method inside my lib folder? Consider the class DoSomething in my lib folder
# inside /lib folder
class DoSomething
def fun
puts @some_text
end
end
class SampleController < ApplicationController
def index
@some_text = "ha ha ha"
DoSomething.new().fun
end
end
This does not print anything. I can pass the value to method but I wanna know is it possible to do it without that?
You can’t access it directly, but you can pass it to the initializer for DoSomething: