Tools for a Modern Ruby Development Setup

Share this article

Tools for a Modern Ruby Development Setup

The initial publication of this article was attributed to the wrong author. This has been fixed and those responsible have been sacked. Sorry David!

Terminal

Web Development has evolved tremendously in the last 20 years. A modern development environment would be unrecognizable to to someone developing Coldfusion in the late ’90s for example. The greater focus on best practices and developer productivity have certainly made software more maintainable, but this comes at the cost of added complexity. To navigate this complexity, a modern development environment is required; this article will outline some of my personal favorite tools.

Tmux

Tmux is a terminal multiplexer (think screen), which means you can have several terminals in the same shell session. It allows you to split panes and move them around and reconnect to a tmux session from a different machine. This particularly shines when it is deployed on a server, as you can start a long-running task, disconnect, and your tmux session will keep running.

The real strength in Tmux for development lies in knowing in which window each of your different tools is running because with some quick window changing shortcuts, you can move so quickly that flow becomes instinctual. To aid this, tmuxinator sets up profiles (protip: bind these to Tmux shortcuts to facilitate easy opening of different types of projects like Rails, Sinatra, etc), which complements Tmux nicely.

Additionally, Tmux is extendable through its plugin ecosystem. Take a look, but I would recommend the Tmux Plugin Manager, tmux-battery, and tmux sensible.

If you are looking for a simple start with Tmux, check out this article.

Fish

Bash is fine and all, but it hasn’t aged very well and better terminal alternatives are available. ZSH is an excellent choice, but I personally lack the motivation to invest time in learning how to configure yet another piece of software. To this end, I would recommend Fish. It has excellent command completion, is fully scriptable, and looks much nicer than Bash. Best of all, it just works out of the box (although there are a couple of minor idiosyncrasies you’ll run into. Also, your Bash aliases won’t work, but translating is straightforward and these are comparatively low setup costs). I particularly enjoy interfacing with Git this way, but I recently discovered the excellent Gitsome, which offers excellent Github integration and unparalleled autocomplete, so I am currently vacillating between the two.

Vim

Vim is the cornerstone of my environment. Heavily customized to speed development, it bears more of a resemblance to a fully fledged (albeit lightweight!) IDE. Let’s walk through some generally useful plugins, and then get to some Ruby-specific ones. You can download my vim dotfiles here.

Navigating a project can be cumbersome. Fortunately, Vim’s rich ecosystem really comes into its own here. For browsing a project, I recommend the excellent Nerdtree. This will give you a browsable tree structure, affording you a neat high-level overview of the current directory and its children. Pressing m while in this view will allow you the ability to delete, create, and rename nodes without ever leaving vim. Sublime stalwarts will enjoy ctrlp; an excellent fuzzy matcher which particularly shines when you have similarly named files, like in a Rails project for example. Finally, I frequently want to access files I have used recently; MRU does exactly this.

While those are some of my favorites, here are some other vim plugins that deserve special mention: * Fugitive: Git integration directly in Vim * Supertab: Code completion * Airline: Pleasant looking status bar * TComment: Quick comment/uncomment functionality * Surround: Wrap the usual vim boundary selections in parenthesis or quotes * Autoclose: Automatically close brackets or quotes * Gundo: Interface to Vim’s well hidden tree structure storing document changes, which frequently proves much more useful than the linear ‘undo’ functionality

Ruby Specific Plugins

First up, you need to ensure your version of Vim is compiled with Ruby:

vim --version | grep ruby

The above command should include a +ruby. If it doesn’t, you need to either recompile Vim with ruby support (relatively trivial) or install a version of Vim with Ruby support, like MacVim. While a lot of the plugins will work without it, you’ll miss out on useful features like autocompletion.

vim-ruby is the first port of call. It adds syntax highlighting, IntelliSense-like autocompletion, and even compiler plugins. This should get you a lot of basic IDE functionality out of the box. It even has erb syntax highlighting!

Tim Pope is the man who has given us several excellent Ruby (and other) plugins. You could do worse than to check out his projects and integrate them into your workflow. If you’re going to get one plugin to aid your Rails development, it should be vim-rails. This plugin brings all the command line functionality directly into Vim, which is tremendously useful when you marry it up with Vim shortcuts. Let’s delve into some useful commands here:

gf – This is a context aware switch that will jump you right into a related file. You can leverage the appropriately named :A (alternate) and :R (related) to go from model to schema, template to helper, and controller to functional test.

Interface with rails on the command line with :Rails (also rake can be accessed via :Rake, if you’re pre-Rails 5.)

You can extract partials by visually selecting an area and leveraging :Rextract <filename>. This seems such a minor feature but is incredibly useful when refactoring a clumsy view.

There are a ton of other useful shortcuts and your time will be well invested in learning them.

vim-dispatch is another Tim Pope creation. This allows you to leverage Tmux to bring asynchronous functionality to Vim. Useful to kick off unit tests without blocking input or opening another pane.

vim-rspec is a lightweight RSpec runner for Vim. I enjoy the mappings if I’m not using Guard.

For further reading on this subject, check out this article which is much more in depth.

Honorable mentions:

  • vim-endwise: automatically appends an end when you input def <function_name>. Think snipmate but without having to invoke the shortcut.
  • vimbundler: wraps bundler, which makes interfacing with it slightly nicer.
  • vim-haml: Cutting edge Vim runtime files for Haml, Sass, and SCSS – unnecessary but nice.

This isn’t really a Vim plugin but I’ll include it here anyway: gem-browse is a Ruby Gem that opens a library’s source file in your editor, which saves time when you need to wade through the source of some obscure library to see why your code isn’t executing as expected.

Docker

Docker is comparatively new technology compared with the others, but no less important. It facilitates easy and platform agnostic deployment by running a ‘container’ within a single Linux instance, avoiding the overhead of starting and maintaining traditional Virtual Machines. Additionally, the isolation afforded by this approach affords an extra layer of protection.

Docker used to be a bit difficult to get started with, necessitating the excellent How to Use Docker on OS X: The Missing Guide, but things are better now. Head over to docker.com to get started.

Guard

I am a huge fan of Guard. While in large projects with huge batteries of tests, it doesn’t shine so much, any rapidly evolving project without this constraint benefits hugely from the instant feedback it provides to developers. By keeping the Spring preloader going, it can dramatically reduce time taken for tests to run, and I would wholeheartedly recommend pairing it with minitest-reporters for more informative test output.

Pry

Pry is a fantastic addition to your gemset. A powerful alternative to irb, it allows command shell integration (git, vim, etc), syntax highlighting and powerful history viewing and replay functionality. Used in tandem with the pry-doc gem, it includes some neat features like show-doc to bring up documentation and show-source to view source of Ruby builtins. It can work well as a debugger and as someone who favors REPL driven development, I find it a breath of fresh air to use compared with the default irb.

Pgcli

With the advent of ORMs, SQL is something I interface with less regularly, which means autocomplete is a real time saver when I can’t remember exactly how to do something. Pgcli (and its cousin Mycli if you’re stuck with mysql) offer this exact functionality and with syntax highlighting to boot. Highly recommended.

Mutt

If you can suffer through what is arguably the most painful configuration process in modern software, Mutt is an excellent choice for command line email access. It uses Vim bindings and I definitely appreciate not having to leave my shell to handle email.

Irssi

I find IRC an invaluable resource, but definitely something that works better in the shell. irssi is my client of choice (be sure to check out the extensions). I also hear good things about weechat.

Summary

We’ve covered a lot of ground here and, as always, there’s a ton more below the surface. Vim is where I spend most of my time, so I’ve spent proportionally much more time customizing it. Researching Tmux and your shell properly is definitely time well-spent. Naturally, this is all personal preference so you’re unlikely to develop using my exact setup, but you should hopefully have a better idea of what is out there and perhaps even integrate something new from here into your workflow.

Frequently Asked Questions (FAQs) about Modern Ruby Development Setup

What are the essential tools for a modern Ruby development setup?

The essential tools for a modern Ruby development setup include a text editor or Integrated Development Environment (IDE), a version control system, and a testing framework. Text editors like Sublime Text or Atom, and IDEs like RubyMine, provide features like syntax highlighting, code completion, and debugging tools. Git is a popular version control system that helps manage and track changes to your code. Testing frameworks like RSpec or Minitest are used to write tests for your code to ensure it behaves as expected.

How do I choose the right text editor or IDE for Ruby development?

Choosing the right text editor or IDE depends on your personal preferences and the specific requirements of your project. Some developers prefer lightweight text editors like Sublime Text or Atom, while others prefer full-featured IDEs like RubyMine. Consider factors like ease of use, performance, available features, and community support when choosing a text editor or IDE.

Why is version control important in Ruby development?

Version control is crucial in Ruby development because it allows you to track and manage changes to your code. With a version control system like Git, you can easily revert back to a previous version of your code if something goes wrong. It also makes it easier to collaborate with other developers, as you can merge changes from different sources without overwriting each other’s work.

What is the role of a testing framework in Ruby development?

A testing framework plays a vital role in Ruby development by allowing you to write tests for your code. These tests ensure that your code behaves as expected and helps prevent bugs and errors. Testing frameworks like RSpec or Minitest provide a structured way to write and run tests.

How can I improve my Ruby development setup?

You can improve your Ruby development setup by using tools that enhance your productivity and code quality. This could include linters like RuboCop, which enforce coding style guidelines, or code formatters like Prettier, which automatically format your code to make it more readable. You could also use productivity tools like tmux or screen, which allow you to manage multiple terminal sessions from a single window.

What are some good resources for learning Ruby?

There are many great resources for learning Ruby, including online tutorials, books, and courses. The official Ruby website provides a wealth of information, including a getting started guide and API documentation. Websites like Codecademy and Udemy offer interactive tutorials and courses for beginners and advanced developers alike.

How can I contribute to the Ruby community?

You can contribute to the Ruby community in many ways, such as by contributing to open source projects, participating in online forums and discussion groups, or attending local meetups and conferences. Contributing to open source projects not only helps improve the tools and libraries available to the community, but also provides a great opportunity to learn from other experienced developers.

What are some common challenges in Ruby development and how can I overcome them?

Some common challenges in Ruby development include understanding the Ruby syntax and conventions, managing dependencies, and debugging code. To overcome these challenges, you can use tools like Pry for debugging, Bundler for managing dependencies, and RuboCop for enforcing coding style guidelines. Additionally, reading and understanding the Ruby documentation can help you become more familiar with the language’s syntax and conventions.

How can I keep up with the latest developments in Ruby?

You can keep up with the latest developments in Ruby by following relevant blogs, newsletters, and social media accounts. Websites like Ruby Weekly and Ruby Inside provide regular updates on the latest news and developments in the Ruby community. You can also follow influential Ruby developers on Twitter or GitHub to stay informed about the latest trends and best practices.

What are some best practices for Ruby development?

Some best practices for Ruby development include following the Ruby style guide, writing tests for your code, using version control, and regularly refactoring your code to improve its readability and maintainability. Using a linter like RuboCop can help enforce the style guide and catch common mistakes. Writing tests ensures that your code behaves as expected, while using version control allows you to track and manage changes to your code. Regularly refactoring your code can help keep it clean, readable, and maintainable.

David BushDavid Bush
View Author

David Bush is a Web Developer who travels the world and writes code. His favourite languages are Clojure, Ruby and Python. He enjoys learning new technologies, beer, good food and trying new things. www.david-bush.co.uk

GlennGprytmuxvim
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week