# Writing Ruby Programs Like a Python Programmer

DevFeed: [Writing Ruby Programs Like a Python Programmer](<https://devfeed.tech/articles/writing-ruby-programs-like-a-python-programmer-28309.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/ruby/2020/02/15/writing-ruby-programs-like-a-python-programmer.html>)

Author: Fuzzygroup

Published: 2020-02-15T00:00:00Z

Content type: article

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Ruby](<https://devfeed.tech/topics/ruby.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [class](<https://devfeed.tech/topics/class.md>), [software-development](<https://devfeed.tech/topics/software-development.md>), [Python](<https://devfeed.tech/topics/python.md>), [Ruby on Rails](<https://devfeed.tech/topics/ruby-on-rails.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>), [rubygems](<https://devfeed.tech/topics/rubygems.md>), [CI/CD](<https://devfeed.tech/topics/cicd.md>)

Tags: [python](<https://devfeed.tech/tags/python.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [writing](<https://devfeed.tech/tags/writing.md>)

## AI overview

For small, continuously running Ruby tools deployed as SystemD services, the author separates a short `main` script from a `Loader` class containing supporting functions. The example project also has a Gemfile, README, deployment script, service file, and service launcher. The author says this structure makes the main loop easier to understand and lets them SSH to the production host, load `loader.rb` in `irb`, and call its class methods while debugging. They use `require_relative` for their own code because ordinary `require` behaved poorly with working-directory differences, and compare the resulting namespace style to Python imports. This is a personal compromise for a lightly staffed project that favors coding time over setting up local Kafka; the author says test coverage has not yet been added.

## Source excerpt

As of late, I have found myself writing a number of what amount to "Non Rails" tools. These are tools that tend to: Run continuously in the background Are deployed as SystemD services on Unix boxes Have the normal issues of coding complexities between development (OSX) and production (Ubuntu) Even though I normally just generate a Rails application for even my command line tools, this project felt like minimalism was called for and, well, I wanted that particular challenge. In the remainder of this blog post, I'm going to talk about what this looks like and what I've learned from spending a few months in the Python world and how I'm applying it here. File Structure Here's a directory listing from one of these tools. The thing to understand is that "ohi" is the abbreviation for the project (which explains why you see it multiple times). ❯ ls -l total 64 -rw-r--r--@ 1 sjohnson staff 189 Feb 24 09:58 Gemfile -rw-r--r-- 1 sjohnson staff 2083 Feb 24 09:58 Gemfile.lock -rw-r--r--@ 1 sjohnson staff 307 Feb 24 10:21 README.md -rwxr-xr-x@ 1 sjohnson staff 111 Feb 24 14:35 deploy.sh -rw-r--r--@ 1 sjohnson staff 3542 Feb 24 14:07 loader.rb -rw-r--r--@ 1 sjohnson staff 1477 Feb 24 14:12 loader_kafka_to_ohi.rb -rw-r--r--@ 1 sjohnson staff 436 Feb 24 10:29 loader_kafka_to_ohi.service -rw-r--r--@ 1 sjohnson staff 125 Feb 24 10:22 loader_kafka_to_ohi.sh Here is the role of each of these pieces: Gemfile / Gemfile.lock - the standard Ruby packages that the tool relies on README.md - the Readme deploy.sh - a shell script that SCP's everything up to a deployment server. Yeah, yeah. I need CI/CD. And it will come but for now this makes deployment easy. loader.rb - the "God" class for this tool (explained below) loader_kafka_to_ohi.rb - the actual main loop for the tool loader_kafka_to_ohi.service - the SystemD service file for this loader_kafka_to_ohi.sh - the shell script called by the SystemD service file It really is About Separating def main From Supporting Functions While all these