Here's what you can do with Code-Runner:
- 40+ languages – Python, Ruby, JavaScript, Java, C++, Go, Rust, and many more
- Instant execution – Write code, run it, see results. No setup needed
- Pass input – Your code can read from stdin, just like a real program
- Command line args – Test how your script handles arguments
- Timeouts – No more infinite loops crashing your app
- Clean output – Get stdout, stderr, and compiler messages separately
gem install ruby-code-runnerrequire 'code-runner'
# Ruby
result = CodeRunner.run('puts "Hello World!"', 'ruby')
puts result[:output] # Hello World!# Python
result = CodeRunner.run('print("Hello Python!")', 'python')
puts result[:output] # Hello Python!# JavaScript
result = CodeRunner.run('console.log("Hello JS!")', 'javascript')
puts result[:output] # Hello JS!# Ruby
result = CodeRunner.run('puts 2 + 2', 'ruby')
puts result[:output] # 4# Python
result = CodeRunner.run('print(3 * 4)', 'python')
puts result[:output] # 12code = <<~PYTHON
name = input("What's your name? ")
print(f"Hello {name}!")
PYTHON
result = CodeRunner.run(code, 'python', stdin: "Monji")
puts result[:output]code = 'puts "Args: #{ARGV.join(", ")}"'
result = CodeRunner.run(code, 'ruby', args: ["hello", "world"])
puts result[:output] # Args: hello, worldresult = CodeRunner.run('print(1 / 0)', 'python')
if result[:success]
puts "ok : #{result[:output]}"
else
puts "err : #{result[:error]}"
endfull list:
Python
Ruby
JavaScript
Java
C
C++
C#
PHP
Go
Rust
Bash
Swift
Kotlin
TypeScript
Dart
R
Perl
Lua
Haskell
Elixir
Erlang
Clojure
Scala
Fortran
Julia
Groovy
| GitHub | monji024 |
| RubyGems | code-runner |
If you find this gem useful, here's how you can support me:
Visit github.com/monji024/code-runner and click the ★ button.