Skip to content

Instantly share code, notes, and snippets.

months = [1,2,3,4,5,6,7,9,10,11,12].to_a.map { |month| Date.new(2018, month) }
months = months.map { |month| month..month.end_of_month }
months.inject([]) do |array, month|
if array.present? && array.last.last + 1.day == month.first
array.push(array.pop.first..month.last)
else
array.push(month)
end
end.map do |range|
[range.first.strftime("%b '%y"), range.last.beginning_of_month.strftime("%b '%y")].join(" - ")
@npezza93
npezza93 / singular_collection_ids_test.rb
Created January 4, 2017 03:45
Example script showing a bug when trying to set singular_collection_ids with a primary key set on relationship
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler 1.10 or later is required. Please update Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
# Activate the gem you are reporting the issue against.