Ask A Question

Notifications

You’re not receiving notifications from this thread.

Today I Learned!

Chris Oliver asked in General

I thought it would be fun to start a thread where we can post the things we've learned recently.

Today I learned that __dir__ returns a full path while File.dirname(__FILE__) returns a relative path thanks to Xavier's recent commit in Rails: https://github.com/rails/rails/commit/de4d8744744acab2dd9db0683ccf784ea45810b2

Reply

Today I learned that you can view the source code of a method that is available in the current context using the show_source command when in a call to binding.irb. To try it out put a binding.irb in an instance method for example. Create an object that responds to that message in your Rails console, call the method, and once you hit the binding.irb you can see what methods are available in the current context with the ls command. Find one that interests you and view the source by calling show_source foo (foo being the name of the method you want to view the source of) and you can quickly view the source code of that method.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,291+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.