NOTE:This blog had a good run, but is now in retirement. If you enjoy the content here, please support Gregory's ongoing work on the ...
class Book def initialize(name) @name = name end def available_for_purchase? copies_remaining > 0 end private def copies_remaining Inventory.count(:book, @name) end end module Inventory extend self def count(item_type, name) item_class(item_type).find_by_name(name).quantity end def re...
You will likely never implement all these aspects in a single class. Even for those aspects you do use, you might not use the same implementations I will present. That’s OK. The implementations presented in this article are intended to cover aspects thoroughly even though you will not...
Directly implemented on Prawn::Document start_new_page, page_count, cursor, render, render_file, bounds, bounds=, move_up, move_down, pad_top, pad_bottom, pad, mask, compression_enabled?, y, margin_box, margins, page_size, page_layout, font_size Included via Prawn::Document::Text text...
When using inheritance like this you are wasting resources (a class in this case) and so far I see only one advantage: changing the constructor is a bit easier because the old implementation is available via super without having to resort to alias or reimplementing member initializati...
Issue #8: Uses for Modules (1 of 4) 2011-04-13 18:00, written by Gregory Brown Originally published as part of the Practicing Ruby newsletter on December 8, 2010. Most of these issues draw inspiration from discussions and teaching sessions at my free online school, Ruby Mendicant Univ...
Practicing Ruby's second volume now freely available 2012-03-26 14:00, written by Gregory Brown Keeping with my promise to release content from my Practicing Ruby journal , I’ve put together a massive link dump of articles from its second volume. Please enjoy them and share them with ...
If you haven’t watched Jim’s talk yet, I’ll remind you to go ahead and do that now. But assuming for some reason you can’t or won’t, you should know that the kinds of complexity that connascence can be used to reason about typically have something to do with coupling. The relationship...
Today, we’ll focus on the question that caused me to write this series in the first place. Many readers were confused by my use of extend self within earlier Practicing Ruby articles, and this lead to a number of interesting questions on the mailing list at the time these articles wer...