Ruby — an Object Oriented Programming Language for all

Ruby is one of the main Object Oriented Programming Languages that is currently out there. Ruby is different from other programming languages in many different ways, one primary way is its naming conventions. Specifically, Ruby has many different names for the same functions, which can prove to be confusing at times, but also can be helpful in bringing in new developers into the coding world and bringing a new sense of creativity to the scene as well.

Ruby Logo
https://logodix.com/

Map vs. Collect

Ruby offers the user the ability to do a transformation on values of an Array with both Map and Collect. Both of these programmatically perform the same operations. Specifically, Map/Collect take in a procedure and perform that procedure on each element within the array that the method is acted on.

  • Output: => [2, 3, 4, 5, 6]
  • Input: [1, 2, 3, 4, 5].collect {|element| element + 1}
  • Output: => [2, 3, 4, 5, 6]

Reduce vs. Inject

Ruby also offers the user the ability to reduce the entire array to a single value. This can be done through the Reduce method or through the Inject method.

  • Output: => 15
  • Input: [1, 2, 3, 4, 5].inject {|sum, element| sum + element}
  • Output: => 15

Find_All vs. Select

Lastly, Ruby offers the user the ability to filter out elements in an array to a sub array. For instance, maybe the user wants to see all even values in an array or maybe the users wants to see all of the values greater than a certain number. Both of these instances can be completed with the use of Find_All or with the use of Select.

  • Output: => [2, 4]
  • Input: [1, 2, 3, 4, 5].find_all {|element| element % 2 == 0}
  • Output: => [2, 4]

Data Engineer