Kotlin to Ruby
Recorder: the polyglot Kotlin adapter (kotlinc + the Java driver). Top-level functions are
recordable. Ktor and Spring (Kotlin) routes are found by analyze; read java.md for Spring.
Constructs
- Null safety:
String?-> may benil;?.->&.;?:->||(when false is not a value) or.nil? ? d : x;!!-> raiseNoMethodError-like errors only where a recorded case shows it. - Errors:
require(cond) { msg }->raise ArgumentError, msg unless cond;check()->RuntimeError(IllegalStateException);error(msg)->raise msg. - Data classes ->
Data.define(value equality,withforcopy). - Sealed classes /
when-> acase ... inpattern match orcaseon class. - Collections:
map/filter/fold/groupBy/associateBy/sumOf/joinToString->map/select/reduce/group_by/index_by/sum/join.listOfis immutable:freezeif mutation would be a bug. - Ktor:
get("/x/{id}") { call.respond(HttpStatusCode.OK, x) }-> route +render json:.
Traps
- Same numeric traps as Java:
Intoverflow wraps,/truncates toward zero,%takes the dividend's sign (remainder),roundToInt()rounds half up toward +infinity (2.5 -> 3,-2.5 -> -2). String.lengthcounts UTF-16 units;substringthrowsStringIndexOutOfBoundsException(->IndexError) where Ruby returnsnil.toInt()on a string raisesNumberFormatException(->ArgumentError, likeInteger(s));toIntOrNull()->Integer(s, exception: false).