0
Извините за вопрос о новичке, но как передать/получить доступ attar_accessor к нескольким классам? в моем примере ниже класс Foo никогда не может видеть обновленные значения из класса Level.Ruby attr_accessor несколько классов
class Level
attr_accessor :level, :speed
end
class Foo
attr_reader :a, :b
def initialize
@x = Level.new()
@a = @x.level
@b = @x.speed
end
def reload
@a = @x.level
@b = @x.speed
end
end
@testa = Foo.new()
@testb = Level.new()
@testb.level = 5
@testb.speed = 55
puts "Value for attr_accessor is:"
puts "#{@testb.level}"
puts "#{@testb.speed}"
puts "#{@testa.a}"
puts "#{@testa.b}"
@testa.reload
puts "#{@testa.a}"
puts "#{@testa.b}"
Что ваш вопрос? –
Хорошая программа. Что за вопрос? – joews