[Sorry for the empty email, an accident...]

Am 13.07.2013 18:55, schrieb Michael W.:
> Okay. Let me try and further explain.   With stack.push(obj) I would
> understand if it said @stack.push(obj) but that actually breaks the
> code. In the add_to_stack method.

Douglas already explained why.

To elaborate further: the following *would* work,
but I would prefer your original code:


module Stacklike

   def stack
     @stack
   end

   def add_to_stack(obj)
     if @stack
       @stack.push(obj)
     else
       @stack = [obj]
     end
   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


-- 
<https://github.com/stomar/>