Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Scaruby: Ruby-like lightweight scripting library for Scala

Join the chat at Build Status Maven Central Scaladoc Reference Status

Scaruby is not a thin layer of but a thick layer of it. Users of Scaruby don't need to know the detail of Instead, Scaruby provides the way to do file I/O independently.


  • Builtin loan pattern
  • Simple operation can be done by simple method call
  • Base64 encode/decode
  • Every SReader/Swriter can be used in for-expression, which is implemented as foreach method.
  • Support reading text/binary content from SURL
  • Minimize overloading! Instead, use type classes or default arguments
  • Additional features will be added as needed


Now Scaruby supports Scala 2.11.X, Scala 2.12.X, and Scala 2.13.X.

Add the following lines to your build.sbt:

libraryDependencies += "com.github.scaruby" %% "scaruby" % "0.6"

If you'd like to use SNAPSHOT version, add the following lines:

resolvers += "Sonatype OSS Snapshots" at ""

libraryDependencies += "com.github.scaruby" %% "scaruby" % "0.7-SNAPSHOT"

and you can use Scaruby like the following:

Read from text file:

import com.github.scaruby._

val content ="file.txt")

Read lines from text file:

import com.github.scaruby._

val lines = SFile.readLines("file.txt")

Read from binary file:

import com.github.scaruby._
val content = SFile.readBytes("files.bin")

Base64 encode/decode:

import com.github.scaruby._

val input = "Hello, World!"
val encoded = SBase64.encode(input.getBytes("UTF-8"))
val decoded = new String(SBase64.decode(encoded), "UTF-8")
assert(input == decoded)

Read from URL:

import com.github.scaruby._
val content = for { 
  r <- SURL("").openReader
} r.readAll

Calculate the average:

import com.github.scaruby.collection._
val seq = Seq(1.0, 2.0, 3.0)
assert(2.0 == seq.average)

upward indexed loop (from 0.6-SNAPSHOT):

import com.github.scaruby.control._
var list: List[Int] = Nil
1.upTo(5){i =>
  list = i :: list
assert(List(5, 4, 3, 2, 1) == list)

list = Nil
1.upTo(5, by = 2) {i =>
  list = i :: list
assert(List(5, 3, 1) == list)

downward indexed loop (from 0.6-SNAPSHOT):

import com.github.scaruby.control._
var list: List[Int] = Nil
5.downTo(1){i =>
  list = i :: list
assert(List(1, 2, 3, 4, 5) == list)

list = Nil
5.downTo(1, by = 2){i =>
  list = i :: list
assert(List(1, 3, 5) == list)

n times loop (from 0.6-SNAPSHOT):

var list: List[Int] = Nil
3.times{i =>
  list = i :: list
assert(List(2, 1, 0) == list)


Ruby-like Lightweight Scripting Library for Scala




No packages published

Contributors 4