Freezing string to improve performance 🙌🏼

Advantage - If you freeze string object, it'll not allocate new memory and it improves app performance by saving time for garbage collection 🔥

Reference - Ruby Optimization with One Magic Comment

Code snippet 📌

def get_object_id
  object = 'Ruby'
  object.object_id
end

puts get_object_id   #=> 70106567869780
puts get_object_id   #=> 70106566368140

# Add following commented line in your file/rails console.

# frozen_string_literal: true
def get_object_id
  object = 'Ruby'
  object.object_id
end

puts get_object_id   #=> 70106483293400
puts get_object_id   #=> 70106483293400