May 13, 2017 by Daniel P. Clark

Don’t Use Objects as Hash Keys in Ruby*

Hashes have been optimized for symbols and strings in Ruby which technically are objects but this article is for revealing how much of a difference this makes when using other objects as hash keys.  There are some cases where this makes a big difference but many times you won’t notice much of a difference. I…

Continue Reading »

February 10, 2015 by Daniel P. Clark

Rails Polymorphic Associations

What is a polymorphic association you might ask?  It’s where an ActiveRecord model can potentially belong to more than one other kind of model record.  So the single instance of your car belongs to you, a person, whereas other cars may individually belong to a car lot, a business. Why do we need it? In…

Continue Reading »

February 4, 2015 by Daniel P. Clark

Using Ruby Object Type Classes to Safely Build Data

When building collections of data you will find situations where the types aren’t what you planned to work with.  And when I say types I’m speaking generically of arrays, hashes, strings, integers, nil, etc.  Everything’s cosy when you know what your getting.  For example putting 10 integers into an Array: arr = [] 10.times do…

Continue Reading »

January 20, 2015 by Daniel P. Clark

Refinements over Monkey-patching

Monkey patching is rather straight forward.  You take an existing object and you apply your own duct tape, glue, nuts and bolts, or even chewing gum.  Or if it’s bad you hit it with a hammer.  No, but more seriously, it’s when you modify something existing from outside it’s original project code. For example you…

Continue Reading »