Author Archives: Laura

Polymorphism in 6 steps

A slightly advanced association in ActiveRecord is called polymorphic association. This usually happens when a model can belong to more than one model, even if it behaves the same way, but it’s easier to understand with an example. Suppose you have a blog that has articles, photos, and events. You want to add comments on...
Read More

Four rules for developers

… according to Sandi Metz, author of POODR. She mentioned these in a Ruby Rougues podcast and I thought they were interesting! 1. Classes can be no longer than one hundred lines of code. 2. Methods can be no longer than five lines of code. 3. Pass no more than four parameters into a method...
Read More

Recursion

A method that calls itself. The only time I ever saw something calling itself was outside of my wonderful apartment in the delightfully urine soaked street underneath a blanket. I could not for the life of me grasp how it worked. Yeah, I got the metaphors. “It’s kind of like Inception. You can’t wake out...
Read More

Prototyping and Inheritance in Javascript

A prototype in Javascript is exactly what it sounds like: a prototype for object to follow.  The best way to explain it would be with an example, of course! We’ll throw in some inheritance while we’re at it. Let’s say we have an an Animal object, that has a name and numLegs, which is a...
Read More

Model validations in Rails

Validations are pretty much a “check” that records won’t be saved unless certain attributes/params meet a specified criteria. They can all done in the models and they can be done in a single line per attribute. For example, if we have a Painting model, inside the class(model) we have: validates :name, presence: true, uniqueness: true...
Read More