Guest User

Untitled

a guest
Aug 17th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. class Dragon
  2. attr_reader :location
  3. attr_accessor :name
  4.  
  5. def initialize(name)
  6. @name, @location = name, 'Far far away'
  7. end
  8.  
  9. def fly_to(location)
  10. @location = location
  11. puts "Dragon #{@name} fly to #{@location}"
  12. self
  13. end
  14.  
  15. def walk_to(location)
  16. @location = location
  17. puts "Dragon #{@name} walk to #{@location}"
  18. self
  19. end
  20. end
  21.  
  22. x = Dragon.new 'Petr'
  23.  
  24. puts "Dragon's name is #{x.name} and his location is #{x.location}"
  25. x.fly_to 'Moscow'
  26. puts "Dragon's name is #{x.name} and his location is #{x.location}"
  27. x.walk_to 'Piter'
  28. puts "Dragon's name is #{x.name} and his location is #{x.location}"
  29. x.name = 'Wall-e'
  30. puts "Dragon's name is #{x.name} and his location is #{x.location}"
Add Comment
Please, Sign In to add comment