Its an alias for !merge which updates the given hash object and returns the updated hash. Basically used to update the value of hash with same key or !merge.

NOTE:  update routine overrides the value of the caller object which keys matches with the parameter pass hash in the update routine.
Usage 1:

  hash1 = { a: 'I am from hash 1'}
  hash2 = { a: 'I am from hash 2'}
   => {:a=>"I am from hash 2"}
   => {:a=>"I am from hash 2"}

usage 2:

  hash1 = { a: 'I am from hash 1'}
  hash2 = { b: 'I am from hash 1'}

    => {:a=>"I am from hash 1", :b=>"I am from hash 1"}

for more details:

Selection sort in ruby

a = [9, 8, 6, 5, 4, 3, 2, 1]

// sorting in ascending order

total_index = a.length - 1
(total_index).times do |i|
  current_top_index = i
  (i + 1).upto(total_index) do |j|
    if a[j] < a[current_top_index]
      temp = a[j]
      a[j] = a[current_top_index]
      a[current_top_index] = temp
a = [1, 2, 3, 4, 5, 6, 8, 9]

Time complexity

Space complexity


Characteristics of Great Code

  • Uses the CPU efficiently (which means the code is fast) Uses memory efficiently (which means the code is small) Uses system resources efficiently
  • Is easy to read and maintain
  • Follows a consistent set of style guidelines
  • Uses an explicit design that follows established software engineering conventions
  • Is easy to enhance
  • Is well-tested and robust (meaning that it works) Is well-documented

extracted from book write great code volume 1.


Bus Factor in software development

For any software project developer are valuable resources. Not all the developers, but in a project there might be some developer who hold the knowledge of project in deep level. They know how to advance project and consequently, when they leave, they can make the project slow down.

This is known as the bus factor. Number of key developers who know project in-depth who would need to be hit by a bus, to send the project into such way that it would be hard to proceed further.

A good example can be taken from bread producing company. For an instance a bread company XYZ has 30 people. They produces bread in 3 steps i.e. mixing ingredients, kneading the dough and baking. In XYZ, 5 people knows how to mix ingredients, all 30 people knows how to knead the dough and 15 people knows how to bake. If all 5 people who knows the secret of ingredients disappear, then the whole team is affected. They cannot produce breads. So the team’s bus factor is 5.

Thus the bus factor is a risk measurement of outcome from not being shared of project knowledge among team members.