ruby - Need to get owner's name of the first suitcase unloaded -


i know need make program below give me owner's name of first suitcase unloaded, when method take_from_plane called on cargohold object. created say_owner_name method in suitcase class, don't know how make connection between suitcase , cargohold, in context.

module stacklike   def stack     @stack ||= []   end   def add_to_stack(obj)     stack.push(obj)   end   def take_from_stack     stack.pop   end end  class suitcase    include stacklike   attr_accessor :name   def initialize(person)     self.name = person     puts "#{person}'s suitcase"   end   def say_owner_name     print name   end end  class cargohold    include stacklike   def load_and_report(obj)     print "loading..."     puts obj.object_id     add_to_stack(obj)   end   def take_from_plane     take_from_stack   end end  ch = cargohold.new s1 = suitcase.new("caio") s2 = suitcase.new("john") s3 = suitcase.new("jack")  ch.load_and_report(s1) ch.load_and_report(s2) ch.load_and_report(s3)  first_unload = ch.take_from_plane puts "the first suitcase unloaded #{first_unload.object_id}."  


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -