DateSlash adds a Ruby refinement that makes year/month/day expressions readable with /.
using DateSlash
2026 / 8
# => 253
2026 / 8 / 18
# => #<Date: 2026-08-18 ...>The first / returns an intermediate object that still behaves like the integer quotient of year / month. The second / converts that intermediate value into a Date only when the expression has exactly three terms and they form a valid calendar date.
Add the gem to your application:
bundle add dateslashOr install it directly:
gem install dateslashRequire the gem and enable the refinement in the scope where you want to use it.
require "dateslash"
using DateSlash
date = 2026 / 8 / 18
date.class
# => Date
prefix = 2026 / 8
prefix.to_i
# => 253The refinement only applies when the left-hand side is a four-digit year, the month is from 1 to 12, and the complete date is valid. Invalid dates and expressions with four or more terms keep Ruby's normal division behavior.
using DateSlash
10 / 2
# => 5
2026 / 13
# => 155
2026 / 2 / 29
# => 34
2026 / 8 / 18 / 2
# => 7After checking out the repo, run:
bin/setup
bundle exec rake testYou can also use bin/console to try the refinement interactively.
To install the gem locally:
bundle exec rake installTo release a new version, update lib/dateslash/version.rb and run:
bundle exec rake releaseThe gem is available as open source under the terms of the MIT License.
Everyone interacting in this project is expected to follow the code of conduct in CODE_OF_CONDUCT.md.