Skip to content

Instantly share code, notes, and snippets.

View therealadam's full-sized avatar
🍔
Building Pingboard. Accepting JavaScript. Still loving Rails. Telling jokes.

Adam Keys therealadam

🍔
Building Pingboard. Accepting JavaScript. Still loving Rails. Telling jokes.
View GitHub Profile
@therealadam
therealadam / with.rb
Created August 26, 2008 22:00
'with' keyword for Ruby, if that's your thing
module Kernel
def with(obj, &block)
obj.instance_eval(&block)
end
end
with 'Hi' do
length # => 2
upcase # => "HI"
downcase # => "hi"
window = 14
latest = Time.parse('12:00 AM')
earliest = today - window.days
issues = Issue.find(:conditions => ['updated_at > ? AND updated_at < ?', yesterday, today])
issues_by_day = Hash.new { |key| self[key] = [] }
issues_by_day = issues.injecting(issues_by_day) do |buckets, issue|
buckets[issue.updated_at.strftime('%m/%d')] << issue