Say I am keeping track of email correspondances. An enquiry (from a customer) or a reply (from a supporter) is embedded in the order the two parties are corresponding about. They share the exact same logic when put into the database.

My problem is that even though I use the same logic, the object classes are different, the model fields I need to call are different, and the method names are different as well.

How do I put methods and objects references in before I actually have to use them? Does a "string\_to\_method" method exists or something like that?

Sample code with commentaries:

```
class Email
  include Mongoid::Document

  field :from, type: String
  field :to, type: String
  field :subject, type: String

  belongs_to :order, :inverse_of => :emails

  def start
    email = Email.create!(:from => "sender@example.com", :to => "recipient@example.com", :subject => "Hello")

    from_or_to = from                  # This represents the database field from where I later on will fetch the customers email address. It is either from or to.
    enquiries_or_replies = enquiries   # This represents a method that should later be called. It is either enquiries or replies.

    self.test_if_enquiry_or_reply(from_or_to, enquiries_or_replies)
  end

  def test_if_enquiry_or_reply(from_or_to, enquiries_or_replies)
    order = Order.add_enquiry_or_reply(self, from_or_to, enquiries_or_replies)
    self.order = order
    self.save
  end
end

class Order
  include Mongoid::Document

  field :email_address, type: String

  has_many :emails, :inverse_of => :order
  embeds_many :enquiries, :inverse_of => :order
  embeds_many :replies, :inverse_of => :order

  def self.add_enquiry_or_reply(email, from_or_to, enquiries_or_replies)
    order = Order.where(:email_address => email.from_or_to).first  # from_or_to could either be from or to.
    order.enquiries_or_replies.create!(subject: email.subject)     # enquiries_or_replies could either be enquiries or replies.
    order
  end
end

```