Advertisement
Guest User

Ruby owner composition

a guest
Apr 29th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.30 KB | None | 0 0
  1. class A
  2.   def initialize(owner)
  3.     @owner = owner
  4.   end
  5.  
  6.   def owner_name
  7.     @owner.class.name.split("::").last
  8.   end
  9.  
  10.   def do_stuff
  11.     puts owner_name
  12.   end
  13. end
  14.  
  15. class B
  16.   def initialize
  17.     @a = A.new(self)
  18.   end
  19.  
  20.   def do_stuff
  21.     @a.do_stuff
  22.   end
  23. end
  24.  
  25. b = B.new
  26.  
  27. b.do_stuff
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement