Exemple de classe senzilla
Font: Ruby Essetntials
Exemple 1
require 'colorize'
class BankAccount
def accountNumber
@accountNumber = "12345"
end
def accountName
@accountName = "John Smith"
end
def initialize ()
end
def test_method
puts "------------------------------".colorize(:light_red)
puts "The class is working"
puts accountNumber.colorize(:light_yellow)
puts "Nom de la persona: " + accountName.colorize(:light_blue)
puts "-----------------------------".colorize(:light_red)
end
end
# Construeix objecte
a = BankAccount.new()
# Imprimeix objecte
a.test_method
print `date`.colorize(:light_red)