Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Dragon
- attr_reader :location
- attr_accessor :name
- def initialize(name)
- @name, @location = name, 'Far far away'
- end
- def fly_to(location)
- @location = location
- puts "Dragon #{@name} fly to #{@location}"
- self
- end
- def walk_to(location)
- @location = location
- puts "Dragon #{@name} walk to #{@location}"
- self
- end
- end
- x = Dragon.new 'Petr'
- puts "Dragon's name is #{x.name} and his location is #{x.location}"
- x.fly_to 'Moscow'
- puts "Dragon's name is #{x.name} and his location is #{x.location}"
- x.walk_to 'Piter'
- puts "Dragon's name is #{x.name} and his location is #{x.location}"
- x.name = 'Wall-e'
- puts "Dragon's name is #{x.name} and his location is #{x.location}"
Add Comment
Please, Sign In to add comment