Created
February 10, 2015 03:38
-
-
Save breim/3b609c779f0d3e295848 to your computer and use it in GitHub Desktop.
OPP Ruby example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Midia | |
| attr_accessor :valor | |
| attr_reader :titulo | |
| def initialize(titulo, valor, categoria) | |
| @titulo = titulo | |
| @valor = valor | |
| @categoria = categoria | |
| end | |
| def to_s | |
| %Q{ Acessando pelo Midia - Título: #{@titulo}, Valor: #{@valor}, Categoria: #{@categoria} } | |
| end | |
| end | |
| class Dvd < Midia | |
| def to_s | |
| %Q{ Acessando pelo DVD - Título: #{@titulo}, Valor: #{@valor}, Categoria: #{@categoria} } | |
| end | |
| end | |
| midia1 = Midia.new('A volta dos que nunca foram','100',:romance) | |
| puts midia1 | |
| dvd1 = Dvd.new('Tranças do rei careca','100',:romance) | |
| puts dvd1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment