[ruby-it] Attributi

Antonio Cangiano acangiano a gmail.com
Lun 2 Feb 2009 17:18:39 CET


class MyClass
  attr_reader :att1, :att2
  attr_writer :att3, :att4
  attr_accessor :att5, :att6

  def a
  end

  def b
  end

  protected
  def c
  end

  def d
  end

  private
  def e
  end

  def f
  end
end

att1 e att2 sono attributi read-only, att3 e att4 sono write-only, e att5 e
att6 sono disponibili sia in lettura sia in scrittura.
I metodi a e b sono pubblici, c e d protetti, e ed f privati.

Ciao,
Antonio

PS: Puoi anche passare dei simboli ai modificatori d'accesso (e.g.,
protected :c, :d).
-- 
http://antoniocangiano.com - Zen and the Art of Programming
http://math-blog.com - Mathematics is wonderful!
http://stacktrace.it - Aperiodico di resistenza informatica
Currently writing "Ruby on Rails for Microsoft Developers" for Wrox.


More information about the Ml mailing list