Preface
As per ruby-lang.org, Ruby is based on programming languages like Perl, Smalltalk, Eiffel, Ada, and Lisp. This book focuses on using Ruby from the command line, similar to Perl one-liners usage.
You'll learn about various command line options and Ruby features that make it possible to write compact cli scripts. Learning to use Ruby from the command line will also allow you to construct solutions where Ruby is just another tool in the shell ecosystem.
Prerequisites
You should be comfortable with programming basics and have prior experience working with Ruby. You should know concepts like blocks, be familiar with string/array/hash/enumerable methods, regular expressions etc. You can check out my free book on Ruby Regexp if you wish to learn regular expressions in depth.
You should also have prior experience working with command line and bash
shell and be familiar with concepts like file redirection, command pipeline and so on.
Conventions
- The examples presented here have been tested with Ruby version 3.0.0 and includes features not available in earlier versions.
- Code snippets shown are copy pasted from bash shell and modified for presentation purposes. Some commands are preceded by comments to provide context and explanations. Blank lines have been added to improve readability, only
real
time is shown for speed comparisons and so on. - External links are provided for further reading throughout the book. Not necessary to immediately visit them. They have been chosen with care and would help, especially during re-reads.
- The learn_ruby_oneliners repo has all the code snippets and files used in examples and exercises and other details related to the book. If you are not familiar with
git
command, click the Code button on the webpage to get the files.
Acknowledgements
- ruby-lang documentation — manuals and tutorials
- /r/ruby/ — helpful forum for beginners and experienced programmers alike
- stackoverflow — for getting answers to pertinent questions on Ruby, one-liners, etc
- tex.stackexchange — for help on pandoc and
tex
related questions - LibreOffice Draw — cover image
- pngquant and svgcleaner for optimizing images
- Warning and Info icons by Amada44 under public domain
- softwareengineering.stackexchange and skolakoda for programming quotes
- mdBook — for web version of the book that you are currently reading
- mdBook-pagetoc — for adding table of contents for each chapter
- minify-html — for minifying html files
A heartfelt thanks to all my readers. Your valuable support has significantly eased my financial concerns and allows me to continue writing books.
Feedback and Errata
I would highly appreciate if you'd let me know how you felt about this book, it would help to improve this book as well as my future attempts. Also, please do let me know if you spot any error or typo.
Issue Manager: https://github.com/learnbyexample/learn_ruby_oneliners/issues
E-mail: learnbyexample.net@gmail.com
Twitter: https://twitter.com/learn_byexample
Author info
Sundeep Agarwal is a lazy being who prefers to work just enough to support his modest lifestyle. He accumulated vast wealth working as a Design Engineer at Analog Devices and retired from the corporate world at the ripe age of twenty-eight. Unfortunately, he squandered his savings within a few years and had to scramble trying to earn a living. Against all odds, selling programming ebooks saved his lazy self from having to look for a job again. He can now afford all the fantasy ebooks he wants to read and spends unhealthy amount of time browsing the internet.
When the creative muse strikes, he can be found working on yet another programming ebook (which invariably ends up having at least one example with regular expressions). Researching materials for his ebooks and everyday social media usage drowned his bookmarks, so he maintains curated resource lists for sanity sake. He is thankful for free learning resources and open source tools. His own contributions can be found at https://github.com/learnbyexample.
List of books: https://learnbyexample.github.io/books/
License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
Code snippets are available under MIT License
Resources mentioned in Acknowledgements section above are available under original licenses.
Book version
1.6
See Version_changes.md to track changes across book versions.