Symbols and Variables in Ruby

Symbols and variables are very different things in Ruby. Symbols are like strings, they’re immutable and behave like constants. All equal symbols point to the same memory location. Variables, on the other hand, are references to some objects and can reference symbols.

a = “test” // a, b variable that points to “test” string 
a = “test”
c = :test // c, d variable that points to :test symbol 
d = :test

> a.object_id == b.object_id // Strings with different instance 
> false

> c.object_id == d.object_id // All symbols are same instance 
> true

Destructuring (assignment) in JavaScript

Destructuring assignment is a syntax in JavaScript (ES6) that enables the unpacking of values from arrays and objects into separate variables.

Regular assignment

Destructured assignment


This Tech Bite was brought to you by Kenan Klisura, Lead Software Engineer at Atlantbh.

Tech Bites are tips, tricks, snippets or explanations about various programming technologies and paradigms, which can help engineers with their everyday job.

Want to discuss this in relation to your project? Get in touch:

Leave a Reply