S
Sam Kong
Hi!
See the following codes.
[1]
class C
attr_accessor :a
def f(v)
@a = v
...
end
end
[2]
class C
attr_accessor :a
def f(v)
a = v
...
end
end
[1] and [2] work exactly same.
I wonder which way is more proper.
In my opinion, if there're accessors (getter and setter), using them in
the class is better than directly accessing the instance data.
However, most codes I've seen access the data directly.
What do you think?
Sam
See the following codes.
[1]
class C
attr_accessor :a
def f(v)
@a = v
...
end
end
[2]
class C
attr_accessor :a
def f(v)
a = v
...
end
end
[1] and [2] work exactly same.
I wonder which way is more proper.
In my opinion, if there're accessors (getter and setter), using them in
the class is better than directly accessing the instance data.
However, most codes I've seen access the data directly.
What do you think?
Sam