• Complain

Sundeep Agarwal - Ruby one-liners cookbook

Here you can read online Sundeep Agarwal - Ruby one-liners cookbook full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2021, genre: Home and family. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

No cover

Ruby one-liners cookbook: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Ruby one-liners cookbook" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Sundeep Agarwal: author's other books


Who wrote Ruby one-liners cookbook? Find out the surname, the name of the author of the book and a list of all author's works by series.

Ruby one-liners cookbook — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Ruby one-liners cookbook" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Ruby one-liners cookbook
Ruby one-liners cookbook

Sundeep Agarwal

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

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:

Twitter: https://twitter.com/learn_byexample

Author info

Sundeep Agarwal is a freelance trainer, author and mentor. His previous experience includes working as a Design Engineer at Analog Devices for more than 5 years. You can find his other works, primarily focused on Linux command line, text processing, scripting languages and curated lists, at https://github.com/learnbyexample. He has also been a technical reviewer for Command Line Fundamentals book and video course published by Packt.

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.

One-liner introduction

This chapter will give an overview of ruby syntax for command line usage and some examples to show what kind of problems are typically suited for one-liners.

Why use Ruby for one-liners?

I assume you are already familiar with use cases where command line is more productive compared to GUI. See also this series of articles titled Unix as IDE.

A shell utility like bash provides built-in commands and scripting features to make it easier to solve and automate various tasks. External *nix commands like grep, sed, awk, sort, find, parallel etc can be combined to work with each other. Depending upon your familiarity with those tools, you can either use ruby as a single replacement or complement them for specific use cases.

Here's some one-liners (options will be explained later):

  • ruby -e 'puts readlines.uniq' *.txt retain only one copy if lines are duplicated from the given list of input file(s)
  • ruby -e 'puts readlines.uniq {|s| s.split[1]}' *.txt retain only first copy of duplicate lines using second field as duplicate criteria
  • ruby -rcommonregex -ne 'puts CommonRegex.get_links($_)' *.md extract only the URLs, using a third-party CommonRegexRuby library
  • stackoverflow: merge duplicate key values while preserving order where I provide a simpler ruby solution compared to awk
  • unix.stackexchange: pair each line of file an example where ruby's vast built-in features makes it easier to write a solution

The main advantage of ruby over tools like grep, sed and awk includes feature rich regular expression engine, standard library and third-party libraries. If you don't already know the syntax and idioms for sed and awk, learning command line options for ruby would be the easier option. Another advantage is that ruby is more portable, given the many differences between GNU, BSD, Mac and other such implementations. The main disadvantage is that ruby is likely to be verbose and slower for features that are supported out of the box by those tools.

Command line options
OptionDescription
-0[octal]specify record separator (\0, if no argument)
-aautosplit mode with -n or -p (splits $_ into $F)
-ccheck syntax only
-Cdirectorycd to directory before executing your script
-dset debugging flags (set $DEBUG to true)
-e 'command'one line of script. Several -e's allowed. Omit [programfile]
-Eex[:in]specify the default external and internal character encodings
-Fpatternsplit() pattern for autosplit (-a)
-i[extension]edit ARGV files in place (make backup if extension supplied)
-Idirectoryspecify $LOAD_PATH directory (may be used more than once)
-lenable line ending processing
-nassume 'while gets(); ... end'
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Ruby one-liners cookbook»

Look at similar books to Ruby one-liners cookbook. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Sundeep Misra - Forgive Me Amma
Forgive Me Amma
Sundeep Misra
No cover
No cover
Sundeep Agarwal
No cover
No cover
Sundeep Agarwal
No cover
No cover
Sundeep Agarwal
No cover
No cover
Sundeep Agarwal
No cover
No cover
Sundeep Agarwal
Sundeep Agarwal - Eagle Luck
Eagle Luck
Sundeep Agarwal
No cover
No cover
Sundeep Agarwal
No cover
No cover
Sundeep Agarwal
No cover
No cover
Sundeep Agarwal
Reviews about «Ruby one-liners cookbook»

Discussion, reviews of the book Ruby one-liners cookbook and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.