Skip to content

muratcakmak/Swift-vs-Ruby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

Swift-vs-Ruby

Comments

Both languages support one-line and multi-line comments

# Ruby 

=begin
  multi-line 
  code comment
=end


// Swift 

/*
  multi-line
  code comment
*/

Constant and Variable declaration

Ruby doesn't have constant. Swift does.

# Ruby

legal_age = 18

// Swift 

let legalAge = 18 //This is a constant

var currentAge = 27 //This is variable

String Interpolation

# Ruby

name = "Oguzhan"
puts "Hello, #{name}."

// Swift

let name = "Oguzhan"
print("Hello, \(name)")

Type Inference

Ruby is a dynamic type language. A variable can store anything: integers, strings, floats, objects. Swift is a type safe language. Compiler yells at your code, if you try to reassing an integer to string variable. However, Swift has a type inference.

# Ruby 
name = "Oguzhan"
name = 89.00

// Swift 
var name = "Oguzhan"
name = 89.00 // Compiler Error!

Further Readings

About

Comparison of Swift and Ruby

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published