DEV Community

Joshua Jones
Joshua Jones

Posted on

Methods, Blocks & Sorting in Ruby

Image description

You call a method just by saying its name. If a method takes arguments, you must define a function. You put the argument in parenthesis when you call it.

ex: def square(n)

splat arguments. Splat arguments are arguments preceded by an asterisk *. This tells the program that the method can receive one or more arguments.

Image description

Blocks are like nameless methods
Blocks can be defined with either the keywords "do, end, or curly braces {}"

Sorting:

  • Most sorting algorithms assume we are sorting an array of items, which involves comparing any two items in the array and deciding which should come first. Image description

Sorting in ascending and descending order:
Image description

Top comments (0)