Junior Track Roadmap

ActiveSupport: extensions & time

This course covers a set of ActiveSupport extensions as they appear in this app's own code. It starts with blank?, present? and presence, including why 0 counts as present and false counts as blank. It compares Time.current with Time.now and reads the Rails source behind them. It explains ActiveSupport::Duration and the beginning_of_day, beginning_of_week and beginning_of_month helpers used in reporting queries. It also covers to_sentence for error messages. It ends with try and the split between core Ruby's except and ActiveSupport's except!.

What you'll learn

  • ✓How blank?, present? and presence treat nil, strings, numbers, booleans and collections
  • ✓Why Time.current returns UTC in a Rails app while Time.now uses the server's local zone
  • ✓How ActiveSupport::Duration works with .days, .hours and .ago, including calendar-aware arithmetic
  • ✓Snapping times to day, week and month boundaries, including weeks that start on Sunday
  • ✓Turning error arrays into readable text with to_sentence and its connector options
  • ✓When try fits better than &., and why except is core Ruby while except! is ActiveSupport
Free preview · Lesson 1 3 min read

blank? and present?: the two cases that surprise everyone

app/models/identity/user.rb, this app's model:

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...