I've seen the Ruby design pattern before, but I've forgotten all about it. Now buy a big talk design mode, it does not seem so boring, by the way the code with Ruby implementation.
#-*-encoding:utf-8-*-#Operation classclassOperation Attr_accessor:number_a,:number_bdefInitialize (number_a = nil, Number_b =nil) @number_a=number_a @number_b=Number_b Enddefresult 0 EndEnd#Addition ClassclassOperationadd <Operationdefresult Number_a+Number_b endend#Subtraction ClassclassOperationsub <Operationdefresult Number_a-Number_b endend#Multiplication ClassclassOperationmul <Operationdefresult Number_a*Number_b endend#Division classclassOperationdiv <OperationdefresultRaise 'the divisor cannot be 0' ifNumber_b = =0 number_a/Number_b endend#Factory classclassoperationfactorydefSelf.create_operate (operate) case operate when'+'operationadd.new () when'-'operationsub.new () when'*'operationmul.new () when'/'operationdiv.new () End Endendoper= Operationfactory.create_operate ('/') Oper.number_a= 1Oper.number_b= 2P Oper.result
"Big talk design mode" Ruby code: Simple Factory mode