FirstDEV blog
  • Home
  • Ruby
  • Ruby On Rails
  • Tips
  • Solutions
  • About
Subscribe

Solutions

We solve problems, so you don't have to!

Ruby-code

Find Duplicate Elements In An Array In Ruby

Detect which values appear more than once in an array using group_by or tally.

Rajan Bhattarai Rajan Bhattarai 1 min read
Ruby-code

Generate A Secure Random Token In Ruby

Generating cryptographically secure random tokens is essential for password reset links, API keys, email verification tokens, and any value that must be unpredictable to an attacker.

Rajan Bhattarai Rajan Bhattarai 1 min read
Ruby-code

Paginate An Array In Ruby Using Each_slice

When displaying large datasets in pages — or processing records in batches — you need to split an array into fixed-size chunks. Ruby’s each_slice handles this cleanly without manual index arithmetic.

Rajan Bhattarai Rajan Bhattarai 1 min read
Ruby-code

Count Word Frequency In A String In Ruby

Counting how often each word appears in a string is a common text-processing task — useful for analytics, content analysis, keyword detection, and building word clouds. Ruby’s Enumerable provides an idiomatic one-liner.

Rajan Bhattarai Rajan Bhattarai 1 min read
Ruby-code

Parse And Format Dates Cleanly In Ruby Without Common Pitfalls

Date and time handling trips up even experienced Ruby developers — timezone confusion, Date vs Time vs DateTime, string parsing that silently returns nil. This covers the clean patterns for parsing, formatting, and

Rajan Bhattarai Rajan Bhattarai 1 min read
Ruby-code

Convert Strings Between Snake_case And Camelcase In Ruby

When bridging Ruby code (which uses snake_case) with JavaScript APIs or JSON payloads (which often use camelCase), you regularly need to convert between the two formats. Ruby and Rails provide clean ways to

Rajan Bhattarai Rajan Bhattarai 1 min read
Ruby-code

Flatten A Deeply Nested Array In Ruby

Arrays in Ruby can be nested arbitrarily deep — arrays of arrays of arrays. flatten collapses them into a single level, but knowing when to flatten fully versus partially is what separates clean

Rajan Bhattarai Rajan Bhattarai 1 min read
Ruby-code

Sort An Array Of Hashes By Multiple Keys In Ruby

Sorting a collection of hashes by a single key is straightforward, but sorting by multiple keys — primary sort by one field, secondary sort by another — requires a slightly different approach using

Rajan Bhattarai Rajan Bhattarai 2 min read
Ruby-code

Find Intersection Of Arrays Or Sets Cleanly In Ruby 3

Ruby 3+ provides elegant ways to find common elements between arrays, sets, or enum collections using intersection (&) or Set#intersection. This is especially useful for filtering, authorization checks, tag matching, or data deduplication.

Rajan Bhattarai Rajan Bhattarai 1 min read
« Newer Posts Page 3 of 4 Older Posts »
FirstDEV blog © 2026
Proudly published with Jekyll & using Jasper2
Latest Posts Twitter
FirstDEV blog

Check viewARU - Brand Newsletter!

Newsletter to DEVs by DEVs - boost your Personal Brand & career! 🚀