Is there any way to read (scan) all the instance variables from the controller's methods?
ex:
I'll define some instance variables in a controller either index or show or custom defined method. I want to know (get) all the instance variable values from one place.
class TestClass
def t1
@v1 = "test"
end
def t2
@v2 = "test1"
end
end
TestClass.instance_variables
=> []
tc = TestClass.new
tc.t1
tc.instance_variable_names
=> ["@v1"]
The above code is working for the class with the custom methods not with default methods (index, show, etc..)
Rails.env
=> "development"
u = UsersController.new
=> #<UsersController:0x00000004233990 @_routes=nil, @_action_has_layout=true, @_headers={"Content-Type"=>"text/html"}, @_status=200, @_request=nil, @_response=nil>
1.9.3p448 :109 > u.index
NoMethodError: undefined method `env' for nil:NilClass