Skip to content

Instantly share code, notes, and snippets.

@efatsi
Created September 28, 2012 21:10
Show Gist options
  • Save efatsi/3802082 to your computer and use it in GitHub Desktop.
Save efatsi/3802082 to your computer and use it in GitHub Desktop.
Refactoring question
def has_a_thing_at(time)
any_events_at?(time) || any_interview_slots_at?(time) || any_free_slots_at?(time)
end
def any_events_at?(time)
events.where("start_time <= ? and end_time > ?", time, time).any?
end
def any_interview_slots_at?(time)
interview_slots.where("start_time <= ? and end_time > ?", time, time).any?
end
def any_free_slots_at?(time)
free_slots.where("start_time <= ? and end_time > ?", time, time).any?
end
########################################################################
def has_a_thing_at(time)
event_type_at?(events, time) || event_type_at?(interview_slots, time) || event_type_at?(free_slots, time)
end
def event_type_at?(event_type, time)
event_type.where("start_time <= ? and end_time > ?", time, time).any?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment