What is duck typing in ruby?

Posted on

Starting out in ruby duck typing is one of those concepts you will hear thrown around. It really is a simple concept to understand. Have no fear! A beer example is here!

class Tinseth
def calculate_ibus
puts "lets calculate ibus with tinseth!"
end
end

class Rager
def calculate_ibus
puts "lets calculate ibus with rager!"
end
end

class Ibu
def calculate_ibus(type)
type.calculate_ibus
end
end

What are polymorphic associations in rails?

Posted on

According to the rails guide it is, “A slightly more advanced twist on associations”. The term polymorphic association is more scary than the actual implementation of it.

Time to get to it and demystify this “slightly more advanced” association.

The Setup
“`language-console
rails g model BeerRecipe name:string style:string
rails g model Ingredients name:string category:string
“`