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.

Dynamic programming
Software DevelopmentTech Bites
December 9, 2022

Dynamic Programming

Dynamic programming is both a mathematical optimization method and a computer programming method. By definition, it is a technique in computer programming that helps to efficiently solve a class of problems with overlapping subproblems and optimal substructure properties. It refers to simplifying a complicated problem by breaking it into simpler…

Leave a Reply