Wednesday, 18 September 2013

Ruby: Comparison Operator as a string

Ruby: Comparison Operator as a string

I am working on a Rails app that allows a user to check off tasks as they
have completed them and I am working on a method that will return past due
tasks and upcoming tasks.
Here is my method in my User model:
def task_notification(notification_type = "past")
return false if tasks.empty?
current_month = Time.now.month
tasks.where(classification: classification).select { |task|
task.due_date < current_month }
end
I am basically trying to do something like this:
operator = notification_type.eql?("past") ? "<" : ">"
tasks.where(classification: classification).select { |task| task.due_date
operator current_month }
obviously the above doesn't work, I am just wondering how to make it work.

No comments:

Post a Comment