-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ba34cf
commit de8954a
Showing
101 changed files
with
373 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Binary file not shown.
Empty file.
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# GET | ||
class Person | ||
attr_reader :name, :age | ||
def initialize(name,age) | ||
@name = name | ||
@age = age | ||
end | ||
end | ||
|
||
# SET | ||
class Person | ||
attr_writer :name, :age | ||
def initialize(name,age) | ||
@name = name | ||
@age = age | ||
end | ||
end | ||
|
||
# GET / SET | ||
class Person | ||
attr_accessor :name, :age | ||
def initialize(name,age) | ||
@name = name | ||
@age = age | ||
end | ||
end |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
p [].class.ancestors | ||
|
||
a = [] | ||
b = ["zero",1,2.0,"bla".length] | ||
c = Array.new | ||
d = Array.new(4){|index| index ** 2} | ||
e = %w{Array de string} | ||
|
||
p a; p b; p c; p d; p e; | ||
|
Empty file.
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# encoding: utf-8 | ||
|
||
class Teste | ||
end | ||
tes = Teste.new | ||
puts tes.class | ||
p tes.methods.sort | ||
puts tes.to_s | ||
|
||
|
||
class Celular | ||
#constantes | ||
TECLAS = 30 | ||
|
||
#variavel de class | ||
@@visor = "digital" | ||
|
||
attr_reader :marca | ||
|
||
def initialize(marca, cor) | ||
@marca, @cor = marca, cor | ||
end | ||
|
||
def self.desligar | ||
true | ||
end | ||
|
||
def discar(numero) | ||
"Discando o numero #{numero}" | ||
end | ||
|
||
def visor | ||
@@visor | ||
end | ||
|
||
end | ||
|
||
# Injetando method a uma class | ||
def Celular.to_s | ||
"metodo dinamico" | ||
end | ||
|
||
p defined? Celular | ||
cel = Celular.new("motorola", "vermelho") | ||
p cel.visor | ||
p Celular.to_s | ||
|
||
|
||
class Phone | ||
end | ||
|
||
# CLASSES DINAMICAS | ||
Tablet = Class.new | ||
p Tablet.ancestors | ||
|
||
|
||
Mobile = Class.new(Phone) | ||
p Mobile.ancestors |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# encoding: utf-8 | ||
|
||
class Teste | ||
end | ||
tes = Teste.new | ||
puts tes.class | ||
p tes.methods.sort | ||
puts tes.to_s | ||
|
||
|
||
class Celular | ||
#constantes | ||
TECLAS = 30 | ||
|
||
#variavel de class | ||
@@visor = "digital" | ||
|
||
attr_reader :marca | ||
|
||
def initialize(marca, cor) | ||
@marca, @cor = marca, cor | ||
end | ||
|
||
def self.desligar | ||
true | ||
end | ||
|
||
def discar(numero) | ||
"Discando o numero #{numero}" | ||
end | ||
|
||
def visor | ||
@@visor | ||
end | ||
|
||
end | ||
|
||
# Injetando method a uma class | ||
def Celular.to_s | ||
"metodo dinamico" | ||
end | ||
|
||
p defined? Celular | ||
cel = Celular.new("motorola", "vermelho") | ||
p cel.visor | ||
p Celular.to_s | ||
|
||
|
||
class Phone | ||
end | ||
|
||
# CLASSES DINAMICAS | ||
Tablet = Class.new | ||
p Tablet.ancestors | ||
|
||
|
||
Mobile = Class.new(Phone) | ||
p Mobile.ancestors |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
if (true) then | ||
puts "test 1" | ||
else | ||
puts "test 1 false" | ||
end | ||
|
||
|
||
if false | ||
puts "test 2" | ||
else | ||
puts "test 2 false" | ||
end | ||
|
||
|
||
if false | ||
puts "test 3" | ||
elsif true | ||
puts "test 3 elsif true" | ||
else | ||
puts "test 3 false" | ||
end | ||
|
||
|
||
if true then puts "test 4 inline" end | ||
|
||
|
||
puts "test 5 inline end line" if true | ||
|
||
|
||
if true | ||
puts "test 6 line one" | ||
puts "test 6 line two" | ||
end |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
# [Array, Enumerable, Object, Kernel, BasicObject] | ||
|
||
ar = [] | ||
ar = Array.new | ||
# cria com 5 elementos nil | ||
ar = Array.new 5 | ||
# cria com 5 elementos 'a' | ||
ar = Array.new 5, "a" | ||
# cria com 4 elements personalizados | ||
ar = Array.new(4){|index| index ** 2} | ||
#array de string | ||
ar = %w{ a b c d } | ||
#array de simbolos | ||
ar = %i{ a b c d } |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
has = {} | ||
has = { name: "Leandro", lastname: "Nunes" } | ||
|
||
has = Hash.new | ||
|
||
# Definir um valor padrão caso uma chave não seja encontrada | ||
h = Hash.new("default value") | ||
|
||
h = {c: 1, b: 2, a: 3} | ||
|
||
h.default("default value") | ||
h.default = "default value" | ||
|
||
h.default_proc = lambda do |hash, key| | ||
hash[key] = "Unknown %s key" % key.inspect | ||
end | ||
puts h[:e] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# A forma que o hash é definido | ||
has = { | ||
name: "Leandro", | ||
lastname: "Nunes" | ||
} | ||
|
||
|
||
# Definir um valor padrão caso uma chave não seja encontrada -> default_proc | ||
h = {c: 1, b: 2, a: 3} | ||
h.default_proc = lambda do |hash, key| | ||
hash[key] = "Unknown %s key" % key.inspect | ||
end | ||
puts h[:e] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#convertendo Objetos para hasg | ||
|
||
class Config | ||
def initialize(text) | ||
@text = text | ||
end | ||
|
||
def to_hash | ||
result = {} | ||
@text.to_s.scan(/^(\w+) *= *(\d+)$/sim) do |name, value| | ||
result[name] = value | ||
end | ||
result | ||
end | ||
end | ||
|
||
config = Config.new %(a = 1\nb = 2\nc = 3) | ||
puts Hash.try_convert(config) |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#As classes Date, DateTime e Time fazem parte da ST | ||
require "date" | ||
date = Date.parse("27/01/2012") | ||
puts date.to_s | ||
puts date.friday? |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class Person | ||
attr_accessor :name, :age | ||
def initialize(name,age) | ||
@name = name | ||
@age = age | ||
end | ||
end | ||
|
||
class Professor < Person | ||
end | ||
|
||
class Aluno < Person | ||
end | ||
|
||
pro = Professor.new("Leandro",32) | ||
alu = Aluno.new("Pedro",20) | ||
|
||
puts "Professor #{pro.name}, Idade: #{pro.age}" | ||
puts "Aluno #{alu.name}, Idade: #{alu.age}" | ||
|
||
# ver o super |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
def saysomething() | ||
puts "Hello" | ||
end | ||
saysomething | ||
|
||
|
||
def saysomething | ||
puts "Hello" | ||
end | ||
saysomething | ||
|
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class Leandro | ||
def fala | ||
"estou falando..." | ||
end | ||
end | ||
pes = Leandro::new | ||
p pes.fala | ||
|
||
#tudo é objeto | ||
#p 10.class | ||
#p "leandro".class | ||
#p true.class | ||
|
||
|
||
#tap executa um bloco, passando um objeto como parâmetro | ||
#langs = [].tap do |a| | ||
# a << "Ruby" | ||
# a << "Python" | ||
# a << "PHP" | ||
#end | ||
#puts langs | ||
|
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class Car | ||
@@wheel = 4 | ||
|
||
def wheel=(num) | ||
@@wheel = num | ||
end | ||
|
||
p defined? @@wheel | ||
end | ||
|
||
class Fiat < Car | ||
def wheel | ||
@@wheel | ||
end | ||
end | ||
|
||
class Ford < Car | ||
def wheel | ||
@@wheel | ||
end | ||
end | ||
|
||
fiat = Fiat.new | ||
ford = Ford.new | ||
|
||
puts fiat.wheel | ||
puts ford.wheel | ||
|
||
|
||
fiat.wheel = 5 | ||
puts fiat.wheel | ||
puts ford.wheel |
Empty file.
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#Variaveis de instancia no receiver padrao | ||
class Person | ||
|
||
def initialize(name) | ||
@name = name | ||
self.class.count = 4 | ||
end | ||
|
||
def self.count=(num) | ||
@count = num | ||
end | ||
|
||
def self.count | ||
@count | ||
end | ||
|
||
def name | ||
@name | ||
end | ||
|
||
end | ||
|
||
Person.count = 3 | ||
pe = Person.new "Leandro" | ||
## Na instancia da Class | ||
p pe.class.count | ||
## Na instancia do Objeto | ||
p pe.name |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#Variaveis são referencias a objetos | ||
#a = "leandro" | ||
#b = a | ||
#puts a.class | ||
#puts "Id de A: #{a.object_id} e id de B: #{b.object_id}" |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.