Imam Hossain

Software Engineer | Ruby On Rails | React | Bangladesh

Ruby Methods: #tap and #then

Recently, I have learned about these two methods in Ruby and find them quite useful. In this post, we will see how to use them with examples. tap tap method helps to perform certain operations while still returning the old object. ['hello', 'world'].join(' ').tap { |message| message.upcase } # "hello world" As we can see, tap doesn’t return its result. Instead the object it was called on was returned. This is useful for logging....

Aug 08, 2022 Β· 2 min

Add a Custom Pry Prompt in your Rails Console

Pry is an awesome debugging tool for Ruby. The gem pry-rails seamlessly integrates Pry with rails. With pry-rails included in the project Gemfile, it opens the pry prompt whenever we run rails console. [1] pry(main)> We can customize this default prompt to show useful information like the current project name & environment name. pry-rails gem provides a custom prompt for just that. Add the following line in your ~/.pryrc file to enable the rails prompt provided by pry-rails gem....

Jan 01, 2022 Β· 2 min