On Friday 01 June 2007 11:02, raja wrote:

> 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
> 


What you have to do is:

class Person
  # you can define
  public
  # , but stuff is public by default when it hasn't been specified yet.

  belongs_to(bla)
  validates_presence_of(hohoho)

  protected

  attr_reader(:genre)

  # As example; validate needs to be protected.  
  def validate

  end

  private

  def private_method

  end
end