Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. Try to create a "Person" model,that we can use the “children” method below.
  2. >> tom = Person.create(name: “Tom”)
  3. >> may = Person.create(name: “May”, parent: tom)
  4. >> syd = Person.create(name: “Syd”, parent: tom)
  5. >> tom.children.map(&:name)
  6. => [“Syd”, “May”]
  7. Furthermore,can you design "grandchildren" method that we can use it like this?
  8. >> wen = Person.create(name: “Wen”, parent: syd)
  9. >> jon = Person.create(name: “Jon”, parent: may)
  10. >> tom.grandchildren.map(&:name)
  11. => [“Wen”, “Jon”]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement