1. 8
  1. 4

    Ruby, another programming language inspired by Perl, can be made to support this syntax too:

    # set local variables at the top level of a file
    cout = $stdout
    endl = "\n"
    cout << "Whatever" << endl;
    # equivalents:
    $stdout.write("Whatever"); $stdout.write("\n")
    # or
    # or
    puts "Whatever" # because the method Kernel#puts calls `$stdout.puts(*args)`

    Or, if you want to this syntax to be usable in multiple files:

    module CPlusPlusConstants
      def cout
      def endl
    # in another file in the directory
    require_relative 'cpp_constants.rb'
    include CPlusPlusConstants
    cout << "Whatever" << endl;

    In Ruby, methods can be called without parentheses, so methods with no parameters that are in scope act just like a Raku “term” as described in this post. In the above code, the Module#include method brings the methods cout and endl into the file’s implicit top-level module.

    Ruby’s IO class already defines a << instance method that backs the << operator, but you could always redefine it, as Ruby’s classes are open for modification:

    class IO
      def <<(value)
        write(value) # calls IO#write