• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Justin Joyce

Practical tips and tutorials about software development.

  • Standing Invitation
  • Featured Posts
  • Latest
  • About

Ruby

Ruby and Rails nil?, empty?, blank?, and present?

Posted Aug 27, 2023 โ€” Updated Jan 10, 2024

Ruby (and Rails) have many ways to test whether something is … present. But each method behaves slightly differently, and some are Ruby-native while some are added by Rails. Here’s the summary, in case you don’t feel like reading the full details below:   .nil? (Ruby) .empty? (Ruby) .blank? (Rails) .present? (Rails) true false NoMethodError […]

Filed Under: Ruby

Ruby’s safe navigation operator (&.)

Posted Apr 16, 2023 โ€” Updated Jan 10, 2024

Ruby’s safe navigation operator (&.) is a nil-safe way to chain operations. Let’s say we have a User class, and that class can have first_name and last_name attributes: Without safe navigation, we’d need a more-verbose if check to accomplish the same thing: If you’re familiar with Javascript, ruby’s safe navigation works just like javascript’s optional […]

Filed Under: Ruby

Find elements in a ruby array

Posted Feb 2, 2023 โ€” Updated Jan 10, 2024

There are several ways to do this, and their outputs differ based on your needs Let’s do a couple of examples. Array.include? Simple: Array.index This method is a bit confusingly named. It gives you the first index at which the given element appears, not the element at the index given. Array.find and Array.detect Two names […]

Filed Under: Arrays, Ruby

Primary Sidebar

Recent Posts

  • Every Built-In Vim Color Scheme (with screenshots)
  • Reverse a string in Python
  • Meeting Cost Calculator
  • Vim find and replace
  • What makes an effective development team

Categories

  • Arrays (5)
  • Command Line (9)
  • Dates (3)
  • Featured (7)
  • Git (7)
  • Golang (5)
  • Javascript (8)
  • Productivity (8)
  • Projects (4)
  • Python (15)
  • Regex (2)
  • Ruby (3)
  • Shell (2)
  • Thoughts (2)
  • Tips (11)
  • Tools (3)
  • Tutorials (1)
  • Vim (4)

Archives

  • July 2024 (1)
  • February 2024 (1)
  • January 2024 (1)
  • December 2023 (1)
  • November 2023 (1)
  • October 2023 (4)
  • September 2023 (1)
  • August 2023 (2)
  • July 2023 (5)
  • June 2023 (3)
  • May 2023 (6)
  • April 2023 (5)
  • March 2023 (5)
  • February 2023 (10)
  • January 2023 (6)
  • December 2022 (7)

Copyright © 2025 ยท Contact me at justin [at] {this domain}

  • Privacy Policy