Created
October 17, 2012 15:08
-
-
Save pjb3/3906056 to your computer and use it in GitHub Desktop.
By using actual class constants for classes, instead of strings, doesn't the create a mutual dependency problem?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'virtus' | |
| class Post | |
| include Virtus | |
| attribute :title, String | |
| attribute :comments, Array[Comment] | |
| end | |
| class Comment | |
| include Virtus | |
| attribute :post, Post | |
| attribute :body, String | |
| end | |
| # I might want to be able to do this | |
| puts Comment.new(:body => "First Comment", :post => {:title => "First Post"}) | |
| # or this | |
| puts Post.new(:title => "First Post", :comments => [{:body => "First Comment"}, {:body => "Second Comment"}]).inspect | |
| # but you can't because depending on which model you define first, Post or Comment, the other one isn't defined yet | |
| # doesn't it need to work like this? | |
| class Post | |
| include Virtus | |
| attribute :title, String | |
| attribute :comments, Array['Comment'] | |
| end | |
| class Comment | |
| include Virtus | |
| attribute :post, 'Post' | |
| attribute :body, String | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment