Skip to content

Instantly share code, notes, and snippets.

@luislavena
Created August 27, 2010 21:02
Show Gist options
  • Save luislavena/14d319fd48f31ee69971 to your computer and use it in GitHub Desktop.
Save luislavena/14d319fd48f31ee69971 to your computer and use it in GitHub Desktop.
class Container < Ohm::Model
attribute :name
list :feeds, Feed
end
class Feed < Ohm::Model
attribute :title
end
c = Container.create(:name => 'Uno')
#<Container:1 name="Uno" feeds=#<List (Feed): []> bars=#<Set (Feed): []>>
c.feeds.unshift Feed.create(:title => 'A')
#=> 1
c.feeds.unshift Feed.create(:title => 'B')
#=> 2
c.feeds.unshift Feed.create(:title => 'C')
#=> 3
c.feeds.key.lrange(0, -1)
#=> ["3", "2", "1"]
c.feeds
#=> #<List (Feed): ["3", "2", "1"]>
c.feeds[0]
#=> nil
c.feeds.all
#=> [#<Feed:3 title="C">, #<Feed:2 title="B">, #<Feed:1 title="A">]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment