Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. class One
  2. attr_reader :array
  3. def initialize(array)
  4. @array = array
  5. end
  6. end
  7.  
  8. class Two < One
  9. attr_reader :array
  10. def initialize
  11. @array = []
  12. end
  13. end
  14.  
  15. array = ["D","E"]
  16. a = One.new(array)
  17. b = Two.new
  18. c = Two.new
  19.  
  20. def place_string(element,location)
  21. if location == "b"
  22. take element, copy it and place it into @array in b
  23. elsif location == "c"
  24. take element, copy it and place it into @array in c
  25. end
  26. end
  27.  
  28. a.place_string("D","b")
  29.  
  30. Output:
  31. a.array = ["D","E"]
  32. b.array = ["D"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement