class Adder def add( a, b ) a.to_f + b.to_f end end class Subtractor def subtract( a, b ) a.to_f - b.to_f end end class Multiplier def multiply( a, b ) a.to_f * b.to_f end end class Divider def divide( a, b ) a.to_f / b.to_f end end class Calculator attr_writer :adder attr_writer :subtractor attr_writer :multiplier attr_writer :divider attr_writer :functions attr_accessor :memory def add( a, b=memory ) @adder.add( a, b ) end def subtract( a, b=memory ) @subtractor.subtract( a, b ) end def multiply( a, b=memory ) @multiplier.multiply( a, b ) end def divide( a, b=memory ) @divider.divide( a, b ) end def function( name, *arguments ) @functions[ name ].compute( *arguments ) end end