class Song
attr_reader :name, :artist, :duration, :play
attr_writer :name, :artist, :duration
def initialize(name, artist, duration)
@name = name
@artist = artist
@duration = duration
@play = false
end
def to_s
"Song: #@name--#@artist (#@duration)"
end
def reproducir
puts @play = true
end
def detener
puts @play = false
end
def prot
puts "Evento Protegido..."
end
def privado
puts "Evento Privado..."
end
public :reproducir, :detener
protected :prot
private :privado
end
song = Song.new("Corazón espinado", "mana", 260)
puts song.to_s
puts song.name
puts song.name = "Como duele"
puts song.name
puts song.reproducir
puts song.detener
viernes, 5 de octubre de 2007
Un codigo de clase de ruby...
Suscribirse a:
Comentarios de la entrada (Atom)
No hay comentarios.:
Publicar un comentario