Swift से Ruby
Recorder: polyglot Swift adapter (swiftc + एक generated driver)। Free functions और static methods record किए जा सकते हैं। Vapor routes की जाँच app record/replay से होती है।
Constructs
throws:throw ValidationError.empty->raise ValidationError, "empty", हर error enum के लिए मेल खाती Ruby class के साथ, या साधारण invalid input के लिएArgumentError।- Optionals:
String?->nil;if let/guard let->return ... if x.nil?;??->.nil? ? d : x; force unwrap!-> सिर्फ़ वहीं raise करें जहाँ कोई recorded case उसे दिखाए। - Structs/enums: value types ->
Data.define; associated values वाले enums -> हर case के लिएData.define+case ... in;Codablekeys JSON names तय करती हैं (CodingKeys)। - Collections:
map/filter/reduce/compactMap/first(where:)/sorted(by:)->map/select/reduce/filter_map/find/sort_by। - Vapor:
app.get("x", ":id") { req in ... }-> route + action;req.parameters.get("id")->params[:id];Abort(.notFound)-> recorded body के साथhead :not_found।
Traps
- Integer overflow wrap होने के बजाय trap (crash) करता है;
&+wrap करता है।/zero की ओर truncate करता है (Ruby floor करता है);%dividend का sign लेता है (remainder)। - Rounding:
rounded()half away from zero है (Ruby काround);.toNearestOrEven->round(half: :even)।String(format: "%.2f")->format("%.2f")। - Strings:
countgrapheme clusters गिनता है (skin tone वाला emoji 1 है); Ruby काlengthcode points गिनता है:s.grapheme_clusters.lengthइस्तेमाल करें। Indexing मेंString.Indexलगता है, ints नहीं। - Dictionary का order random होता है: जहाँ output उससे आया हो वहाँ sort करें।