# 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: tutorial

Language: en

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

Topics: [Ruby](<https://devfeed.tech/topics/ruby.md>), [Development](<https://devfeed.tech/topics/development.md>), [systemd](<https://devfeed.tech/topics/systemd.md>), [Unix](<https://devfeed.tech/topics/unix.md>), [Ubuntu](<https://devfeed.tech/topics/ubuntu.md>), [Shell](<https://devfeed.tech/topics/shell.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>)

Tags: [command-line](<https://devfeed.tech/tags/command-line.md>), [development](<https://devfeed.tech/tags/development.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [python](<https://devfeed.tech/tags/python.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [shell](<https://devfeed.tech/tags/shell.md>), [systemd](<https://devfeed.tech/tags/systemd.md>), [ubuntu](<https://devfeed.tech/tags/ubuntu.md>), [unix](<https://devfeed.tech/tags/unix.md>)

## AI overview

The article explains how the author structures minimal non-Rails Ruby tools that run continuously as systemd services on Unix systems. It covers the project file layout, deployment script, main loop, and separation of def main from supporting functions, drawing on practices learned from Python.

## 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