Skip to content

Instantly share code, notes, and snippets.

@breim
Created February 10, 2015 03:38
Show Gist options
  • Select an option

  • Save breim/3b609c779f0d3e295848 to your computer and use it in GitHub Desktop.

Select an option

Save breim/3b609c779f0d3e295848 to your computer and use it in GitHub Desktop.
OPP Ruby example
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