[Rails] Check the instance variables and local variables of the file you are browsing

Conclusion

Rails.logger.info(self.instance_variables)
Rails.logger.info(binding.eval("local_variables"))

With the above code, you can output instance variables and local variables as INFO logs. When you want to check the big picture and variables that can be used in the project you see for the first time.

Commentary

Whether it's a Rails controller or a view file, You can use the value of self.instance_variables in the form of the instance variable @var. The binding object is according to here

Objects that represent environmental information such as variables and methods

That thing. You can get local variables by taking "local_variables" as an argument with the eval method.

Reference site

ruby-lang.org: Object section ruby-lang.org: binding section UK MILK: Explanation of binding

Recommended Posts

[Rails] Check the instance variables and local variables of the file you are browsing
[Java Silver] What are class variables instance variables and local variables?
[Rails] Check the contents of the object
Check the migration status of rails
Item 57 Minimize the scope of local variables
Item 57: Minimize the scope of local variables
Check the version of the JDK installed and the version of the JDK enabled
What are the advantages of DI and Thymeleaf?
[Java] Check the JDK version of the built war file
SSL in the local environment of Docker / Rails / puma
Are you using the default method of the interface properly?
What if the results of sum and inject (: +) are different?
Command to check the number and status of Java threads
Change the file name and output destination of the JavaVM error file
How to check the extension and size of uploaded files
Method definition location Summary of how to check When defined in the project and Rails / Gem
Difference between variables and instance variables
[Environment variables] What are rails environment variables?
About instance variables and attr_ *
[Rails] Delete the migration file
[Rails] How to get the URL of the transition source and redirect
Read the first 4 bytes of the Java class file and output CAFEBABE
[Rails] Read the RSS of the site and return the contents to the front
Is the version of Elasticsearch you are using compatible with Java 11?