I am trying to figure out the best way to use multiple parameters in Ruby. The problem is that I am using two types of parameters: Event and User. Sometimes the method needs one User:
postAccept.replaceVariables(sally)
Sometimes it needs two Users:
deleteGuest.replaceVariables(sally, tom)
Sometimes it needs an Event and two Users:
addUserToEvent.replaceVariables(mEvent, tom, sally)
And last, sometimes it needs one Event and one User:
addnonbookable.replaceVariables(event1, carl)
Here is what I am doing currently in regard to the method:
def replaceVariables(*event)
if event.size <=2
if event[0].include?('entryId')
event1 = event[0]
my = event[1]
else
my = event[0]
their = event[1]
end
else
event1 = event[0]
my = event[1]
their = event[2]
end
...
The problem is, I can't figure out a way to differentiate between the user and the event. In the example above, I tried to determine if the object has a specific key, or value, but I get NoMethodError.
Can someone tell me what I'm doing wrong, or show me a way to keep things dynamic and flexible?