R
raja
I know this could be naive but still:
class Person
attr_reader :genre
protected :genre
def psedonym
@name
end
end
In the class above, I can declare variable genre to be protected,
but when I try to do the same for variable name, I get this error
another.rb:3:in `protected': undefined method `Person' for class
`Person' (NameError)
And the same error props up when I comment the line #attr_reader :genre
It appears that i have to provide accessors for the variables before
declaring access modifiers;
and which in fact are "methods", thus IS IT IMPOSSIBLE TO DECLARE ACCESS
MODIFIERS FOR VARIABLES ?
Can Anyone Clarify??
Thanks
Raja
class Person
attr_reader :genre
protected :genre
def psedonym
@name
end
end
In the class above, I can declare variable genre to be protected,
but when I try to do the same for variable name, I get this error
another.rb:3:in `protected': undefined method `Person' for class
`Person' (NameError)
And the same error props up when I comment the line #attr_reader :genre
It appears that i have to provide accessors for the variables before
declaring access modifiers;
and which in fact are "methods", thus IS IT IMPOSSIBLE TO DECLARE ACCESS
MODIFIERS FOR VARIABLES ?
Can Anyone Clarify??
Thanks
Raja