Today I Learned

hashrocket A Hashrocket project

Change your current context

You can change the context of your console session by using the cd just like you would change the context of your directory.

Here is an example.

# Grab an object, in our example a customer.
c = Customer.all.sample

# Now, 'cd' in to that object.
cd c

# From here you will notice that we are now within 
# the context of our object and can call methods on it directly.

pry(<Customer>):1> first_name
=> "Peter"
pry(<Customer>):1> last_name
=> "Parker"

I found this cool tip, as well as some others in this awesome blog post.

See More #rails TILs
Looking for help? Hashrocket has been an industry leader in Ruby on Rails since 2008. Rails is a core skill for each developer at Hashrocket, and we'd love to take a look at your project. Contact us and find out how we can help you.