A scala goodies for rubyist.
This provides following features those are well-known to rubyist.
- using
- Object#tap
- Int#times
- rescue
- md5
- Pathname#{read,write}
- Hashname
- Host,CurrentHost
- String#chomp
- Tempfile
- NKF
import sc.ala.rubyist.Using._
import java.io.ByteArrayOutputStream
using(new ByteArrayOutputStream) { out =>
...
}
// out.close() will be automatically called
import sc.ala.rubyist.Tap._
val props = new java.util.Properties().tap{_.put("port", "80")}
// => java.util.Properties = {port=80}
import sc.ala.rubyist.Times._
3 times { println("ok") }
import sc.ala.rubyist.Rescue._
val num = "1".toInt // => 1
val num = "x".toInt // java.lang.NumberFormatException
val num = "x".toInt rescue 0 // => 0
import sc.ala.rubyist.Digest
Digest.MD5.hexdigest("ruby") // => "58e53d1324eef6265fdb97b08ed9aadf"
import sc.ala.rubyist.Pathname
val log = Pathname("log/langs.txt")
log.exists // => false
log.parent.mkpath
log.write("Ruby\nScala")
log.exists // => true
log.read() // => "Ruby\nScala"
log.readlines() // => List("Ruby", "Scala")
Pathname("hello.txt.sjis", "Shift_JIS").read // with charset
import sc.ala.rubyist.Hashname
val hash = Hashname("data/users/910.xml")
hash.path // => "data/users/e/20/5ee/e205ee2a5de471a70c1fd1b46033a75f/910.xml"
hash.write("...") // write given string into above file
import sc.ala.rubyist.CurrentHost
CurrentHost.name // => moa
CurrentHost.address // => 192.168.1.5
import sc.ala.rubyist.String._
"abc\n".chomp // => "abc"
import sc.ala.rubyist.Tempfile
Tempfile("foo"){ tmp:Pathname =>
tmp.write("hello")
}
- This module directly invokes "nkf" external program, so it should be installed.
import sc.ala.rubyist.NKF
val utf8_text = NKF.nkf("-w", sjis_text)
- tested on scala 2.11.7
Authors: [email protected] Links: http://github.com/maiha/rubyist (forked from s21g/rubyist)