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

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

Image of PulumiUP 2025

Explore What’s Next in DevOps, IaC, and Security

Join us for demos, and learn trends, best practices, and lessons learned in Platform Engineering & DevOps, Cloud and IaC, and Security.

Save Your Spot

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay