"Ruby" (External Evaluation System)

Details

  • Ruby Version 2.0 and higher is supported.
  • Ruby is an open source, dynamic programming language with a focus on simplicity and productivity.
  • To configure Ruby for use in the Wolfram Language, follow the instructions from the Configure Ruby for ExternalEvaluate workflow.

ExternalEvaluate Usage

  • ExternalEvaluate["Ruby",code] executes the code string in a Ruby REPL and returns the results as a Wolfram Language expression.
  • ExternalEvaluate["Ruby""String",code] executes the code string in a Ruby REPL and returns the output as a Wolfram Language string.

Data Types

  • The following Ruby built-in types are supported:
  • ArrayListarray of values
    BigDecimalRealarbitrary-precision real number
    BignumIntegerarbitrary-sized integer
    booleanTrue|FalseBoolean values
    ComplexComplexcomplex number
    FixnumIntegermachine-size number
    FloatRealreal-valued number
    HashAssociationassociative array
    nilNullnull value
    RationalRationalrational number
    StringStringsequence of character values

Usage Notes

  • String templates (<**>) can be used to evaluate and insert Wolfram Language expressions into the Ruby code string.

Examples

open allclose all

Basic Examples  (3)

Evaluate 2+2 in Ruby and return the result:

Arrays are returned as lists:

Type > and select Ruby from the drop-down menu to get a code cell that uses ExternalEvaluate to evaluate:

[1,2,3,4].map { |n| n * 2 }

Scope  (1)

Start a session:

Concatenate strings in Ruby and return the result:

Hashes in Ruby are returned as associations:

Close the session:

Introduced in 2020
 (12.1)