0
Did Ruby accessor stop working or am I doing something wrong?
Yesterday I was learning about accessory for Ruby and seemed to get it work in one of my codes but now when I try again there is no output. I might remember wrong but yesterday attr_accessor had blue font for the accessed. I would appreciate an answer. class Something attr_accessor :number def initialize(number) @num=number end end number1=Something.new(10) puts number1.number
3 ответов
+ 3
You have made a small error. The code works like this:
class Something
attr_accessor :num
def initialize(number)
@num=number
end
end
number1=Something.new(10)
puts number1.num
+ 3
You are welcome. I like questions like these.
0
Thank for your answer. That fixed it.
Much appreciated.