Ruby Interpreter
This online Ruby interpreter allows you to execute Ruby code directly in your browser. It's a convenient tool for testing snippets, learning the language, or quickly running small Ruby scripts without needing a local Ruby installation.
Basic Usage
The simplest way to use this interpreter is to paste your Ruby code into the code block below and click the "Run" button. The output will be displayed below the code.
# ruby
# Interpreter of object-oriented scripting language Ruby
# Invoke Ruby; a dynamic, reflective, object-oriented, general-purpose
# programming language; from the command line to run the provided script.
ruby foo.rb
# Execute Ruby code directly from the command-line.
ruby -e 'puts "Hello world"'
# The `-n` switch allows Ruby to execute code within a `while gets` loop.
ruby -ne 'puts $_' file.txt
# Beware that with the `-n` switch, `$_` contains newline character at the end.
# With the addition of the `-l` switch, each line read has the aforementioned
# newline character removed.
ls | ruby -lne 'File.rename($_, $_.upcase)'
# The `-p` switch acts similarly to `-n`, in that it loops over each of the
# lines in the input, after your code has finished; it always prints the value
# of `$_`.
#
# The following example replaces `e` with `a`.
echo "eats, shoots, and leaves" | ruby -pe '$_.gsub!("e", "a")'
# BEGIN block executed before the loop.
echo "foo\nbar\nbaz" | ruby -ne 'BEGIN { i = 1 }; puts "#{i} #{$_}"; i += 1'
Advanced Features
This interpreter supports a wide range of Ruby features, including:
- Standard library functions
- External libraries (with appropriate setup)
- File I/O
- Network operations (with appropriate security considerations)