S
Sylvester T Cat
This is probably trivial for the pros here, but
I have a class
class MyClass
attr_accessor :raw_vehicle_data
def parse_raw_vehicle_data
@raw_vehicle_data = [0,1,2,3,4]
puts raw_vehicle_data.size # => gives proper size of the array
(i.e. size > 0)
# do other stuff with raw_vehicle_data
end
end
irb(main):019:0> my_class = MyClass.new
=> #<MyClass:0x00000102005f98>
irb(main):020:0> my_class.parse_raw_vehicle_data
5 #<= this value I expect, but it's not assigned to my "instance
variable"
=> nil
irb(main):021:0> my_class.raw_vehicle_data.size
=> nil
If I change the line from raw_vehicle_data = [0,1,2,3,4] to
@raw_vehicle_data = [0,1,2,3,4], then everything works properly, but I
thought attr_accessor gave me access to the function
"raw_vehicle_data=" that would assign to an instance variable.
Apparently I'm wrong, but not sure why.
Thanks!
I have a class
class MyClass
attr_accessor :raw_vehicle_data
def parse_raw_vehicle_data
@raw_vehicle_data = [0,1,2,3,4]
puts raw_vehicle_data.size # => gives proper size of the array
(i.e. size > 0)
# do other stuff with raw_vehicle_data
end
end
irb(main):019:0> my_class = MyClass.new
=> #<MyClass:0x00000102005f98>
irb(main):020:0> my_class.parse_raw_vehicle_data
5 #<= this value I expect, but it's not assigned to my "instance
variable"
=> nil
irb(main):021:0> my_class.raw_vehicle_data.size
=> nil
If I change the line from raw_vehicle_data = [0,1,2,3,4] to
@raw_vehicle_data = [0,1,2,3,4], then everything works properly, but I
thought attr_accessor gave me access to the function
"raw_vehicle_data=" that would assign to an instance variable.
Apparently I'm wrong, but not sure why.
Thanks!