Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Following are some things I found in my collection of obscure Ruby.</p> <p>So, in Ruby, a simple no-bells implementation of the Unix command <code>cat</code> would be:</p> <pre><code>#!/usr/bin/env ruby puts ARGF.read </code></pre> <p><a href="http://ruby-doc.org/core-2.4.0/ARGF.html" rel="noreferrer"><code>ARGF</code></a> is your friend when it comes to input; it is a virtual file that gets all input from named files or all from STDIN.</p> <pre><code>ARGF.each_with_index do |line, idx| print ARGF.filename, ":", idx, ";", line end # print all the lines in every file passed via command line that contains login ARGF.each do |line| puts line if line =~ /login/ end </code></pre> <p>Thank goodness we didn’t get the diamond operator in Ruby, but we did get <code>ARGF</code> as a replacement. Though obscure, it actually turns out to be useful. Consider this program, which prepends copyright headers in-place (thanks to another Perlism, <code>-i</code>) to every file mentioned on the command-line:</p> <pre><code>#!/usr/bin/env ruby -i Header = DATA.read ARGF.each_line do |e| puts Header if ARGF.pos - e.length == 0 puts e end __END__ #-- # Copyright (C) 2007 Fancypants, Inc. #++ </code></pre> <p>Credit to:</p> <ul> <li><a href="http://www.oreillynet.com/ruby/blog/2007/04/trivial_scripting_with_ruby.html#comment-565558" rel="noreferrer">http://www.oreillynet.com/ruby/blog/2007/04/trivial_scripting_with_ruby.html#comment-565558</a></li> <li><a href="http://blog.nicksieger.com/articles/2007/10/06/obscure-and-ugly-perlisms-in-ruby" rel="noreferrer">http://blog.nicksieger.com/articles/2007/10/06/obscure-and-ugly-perlisms-in-ruby</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload