From 3a9900542b55aed51ebf4bae3c4f6d9a7795ef5a Mon Sep 17 00:00:00 2001 From: Joshua Clayton Date: Tue, 24 Apr 2012 10:20:37 -0500 Subject: [PATCH] Favor composition over inheritance for the JsonStrategy example --- GETTING_STARTED.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/GETTING_STARTED.md b/GETTING_STARTED.md index 3733b01..ad95c4e 100644 --- a/GETTING_STARTED.md +++ b/GETTING_STARTED.md @@ -782,9 +782,15 @@ Inheritance can occasionally be useful; here's an example of inheriting from `FactoryGirl::Strategy::Create` to build a JSON representation of your model. ```ruby -class JsonStrategy < FactoryGirl::Strategy::Create +class JsonStrategy + def initialize + @strategy = FactoryGirl.strategy_by_name(:create).new + end + + delegate :association, to: :@strategy + def result(evaluation) - super.to_json + @strategy.result(evaluation).to_json end end ```