From: sto.mar@... Date: 2013-07-14T01:39:23+09:00 Subject: Re: Module Confusion Am 13.07.2013 17:48, schrieb Michael W.: > The below code works. Question though. How does add_to_stack acess the > @stack instance variable going through the method stack? In this case > is stack variable looked at as literally the array? > > Thanks! Michael the Ruby Newby:) > > ------------ > > module Stacklike > > def stack > @stack ||=[] > end > > def add_to_stack(obj) > stack.push(obj) > end > > end > > class Stack > include Stacklike > end > > s = Stack.new > > s.add_to_stack("item one") > s.add_to_stack("item two") > > puts s.stack I'm confused about your confusion. The #stack method simply returns the @stack array (by reference), and push modifies it... Regards, Marcus --