Skip to content

Go to Ruby

Recorder: the polyglot Go adapter (a generated driver per function, go build). Frameworks: net/http, Gin, Echo, Fiber and chi routes are found by analyze.

Constructs

  • Errors as values: return 0, fmt.Errorf("bad input %q", s) -> raise ArgumentError, ... (the recorder reports a returned non-nil error as a raise). Sentinel errors (var ErrNotFound = errors.New(...)) -> class NotFound < StandardError. panic -> raise (RuntimeError).
  • Multiple returns -> an array or a small Data.define, unless the second value is the error.
  • Zero values: an unset int is 0, string is "", a nil slice marshals to JSON null while an empty slice marshals to []. Match the recorded JSON exactly.
  • Structs -> Data.define / Struct; JSON tags (json:"user_id,omitempty") decide the keys and whether zero values are dropped: port omitempty with compact/explicit checks.
  • Maps: iteration order is random in Go; the recorder shows a sorted or noisy order. Sort before output wherever the original's output came from a map.
  • Goroutines/channels -> sequential code, or Active Job when they were background work.
  • Handlers: w.WriteHeader(201); json.NewEncoder(w).Encode(x) -> render json: x, status: :created. Gin c.JSON(200, gin.H{...}) -> render json: {...}. http.Error(w, msg, 400) writes msg + "\n" as text/plain: render plain: "#{msg}\n", status: :bad_request.
  • database/sql, sqlx, GORM -> ActiveRecord on the same tables.

Traps

  • Integer types: int32/int64/uint8 overflow and wrap; Ruby never does. Port the wrap only where a recorded case reaches it. Integer division truncates toward zero (-7 / 2 == -3): Ruby floors; use .fdiv(b).truncate. % takes the dividend's sign: remainder.
  • Rounding: math.Round(-2.5) == -3 (half away from zero) like Ruby's round. math.RoundToEven -> round(half: :even). fmt.Sprintf("%.2f") -> format("%.2f").
  • Strings are bytes: len(s) counts bytes, s[i] is a byte, for i, r := range s walks runes. Ruby length counts characters: use bytesize / byteslice where the original uses bytes.
  • strings.Title, strings.ToUpper are Unicode-aware like Ruby's upcase; strings.Fields -> split (no argument).
  • Floats in JSON: Go writes 1 for a float64 holding 1.0; recordings show it as an int.
  • time.Time marshals as RFC 3339 with nanoseconds: iso8601(9) and trim trailing zeros like Go.
Edit this page on GitHub →