Tech: Rails, Ruby, Hirb gem, CLI
Problem: Want to auto-load Hirb gem in Rails console... in 3 different environments (Docker container, work Mac, personal Mac)... experiencing a different scenario in each environment!
Code (Docker Container)
This one was easy and worked instantly... add gem 'hirb' to Gemfile. Add .irbrc file to the project root folder. For console output configuration, add hirb.yml file to config folder.
Code (work Mac MacBook Pro OS X Yosemite 10.10.5, Mid 2015)
I expected to replicate the setup locally and have success.... nope! When launching the Rails console, I still had to manually activate the Hirb gem.... after some reading, I discovered the .irbrc in this case should be in the user root directory. I navigated there, created .irbrc file... and it was no where to be found...
ls => no file! ???
How about ls -a ? There it is!
cli => vim .irbrc and copy in the required code (i for insert, make changes, esc, :wq), then reload cli => source ~/.irbrc
Code (personal MacBookPro OS X Yosemite 10.10.5, Mid 2012)
Now, I really expected this to go smoothly after the above install, but it was the most difficult of the three. In this case, I already had an .irbrc file in my root folder, so I added the Rails env code. First though, I copied the original for reference just in case. cp .irbrc .irbrc_original
When trying to reload with source ~/.irbrc, seeing the following error:
After playing around with no success... back to Google. I discovered a better alternative to finding out what is wrong. I used ruby ~/.irbrc to launch the file and maybe see a different set of error msgs... hopefully, more specific...
Success! Clearing out some of the erroring code allowed a successful launch of the console with Hirb auto-loaded.
Questions remain though...
- On personal mac, I was surprised to see .irbrc already in the user root folder.
- Not sure why those particular lines were erroring, and if by removing them, will it cause problems elsewhere?
- The source error remained on my personal mac although I successfully auto-loaded Hirb in the Rails console. Why?
- Why does Docker look for .irbrc in the project root, and local machine in the user root?
- I would like to explore and implement the awesome_print gem.