Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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”]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement