Skip to content

Instantly share code, notes, and snippets.

@belguzmani
Last active August 29, 2015 14:19
Show Gist options
  • Save belguzmani/9e7e059c46be67a8a977 to your computer and use it in GitHub Desktop.
Save belguzmani/9e7e059c46be67a8a977 to your computer and use it in GitHub Desktop.
Ruby Object acts as Array
class Conversation
has_many :messages
def << m
self.messages << m
end
end
class Message
belongs_to :conversation
end
# usage
conversation = Conversation.find(id)
conversation << Message.new content: 'Hi There'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment