Created
October 13, 2015 13:29
-
-
Save minjindang/664462731dc94e603c46 to your computer and use it in GitHub Desktop.
Ruby on Rails
This file contains 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
Try to create a "Person" model,that we can use the “children” method below. | |
>> tom = Person.create(name: “Tom”) | |
>> may = Person.create(name: “May”, parent: tom) | |
>> syd = Person.create(name: “Syd”, parent: tom) | |
>> tom.children.map(&:name) | |
=> [“Syd”, “May”] | |
Furthermore,can you design "grandchildren" method that we can use it like this? | |
>> wen = Person.create(name: “Wen”, parent: syd) | |
>> jon = Person.create(name: “Jon”, parent: may) | |
>> tom.grandchildren.map(&:name) | |
=> [“Wen”, “Jon”] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment