Skip to content

Instantly share code, notes, and snippets.

@parsonsmatt
Created July 23, 2015 03:35
Show Gist options
  • Save parsonsmatt/66b68c621a76b2b97ab4 to your computer and use it in GitHub Desktop.
Save parsonsmatt/66b68c621a76b2b97ab4 to your computer and use it in GitHub Desktop.
class Object
def send_array(*messages)
messages.reduce(self) { |obj, message| obj.send(*message) }
end
def send_hash(**messages)
send_array(messages.map { |k, v| [k, *v] })
end
def multi_send(*messages)
if messages.all? { |message| Hash === message }
send_hash(*messages)
else
send_array(*messages)
end
end
end
5.multi_send(:days, :ago, :to_date, [:eql?, 5.days.ago.to_date])
# => true
5.multi_send( :+ => 5, :- => 8, eql?: 2)
# => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment