Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDrew Butcher
33,160 Pointsdelete entry notation
Before I saw the way Kenneth Love typed delete entry
entry.delete_instance()
I tried
Entry.delete_instance(entry)
It seem to work! Are they the same?
1 Answer
Stephen Link
3,685 PointsThey can be the same. I haven't been able to dig out the code for the Entry class so I won't say for sure that they are the same. But they could be. If you think about it "entry" is an instance of the Entry class. So entry.delete_instance() is just calling the delete_instance method on that particular instance of the Entry class while Entry.delete_instance(entry) is going back to the class itself, calling the delete_instance method, and passing in the entry as the thing to be deleted. Depending on how that method is written (and as I said I haven't pulled out the code so I don't know for sure) these two things can indeed result in the same behavior.
arshin
17,770 Pointsarshin
17,770 PointsYour method, i.e. Entry.delete_instance(entry) is better in terms of the hierarchical consistency..