Skip to content

Commit

Permalink
atualizações
Browse files Browse the repository at this point in the history
  • Loading branch information
LeandroSNunes committed Sep 25, 2015
1 parent 1ba34cf commit de8954a
Show file tree
Hide file tree
Showing 101 changed files with 373 additions and 0 deletions.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified Vagrantfile
100644 → 100755
Empty file.
Empty file modified book_store/lib/biblioteca.rb
100644 → 100755
Empty file.
Empty file modified book_store/lib/livro.rb
100644 → 100755
Empty file.
Empty file modified book_store/lib/loja_virtual.rb
100644 → 100755
Empty file.
Empty file modified book_store/lib/relatorio.rb
100644 → 100755
Empty file.
Binary file modified lang/.DS_Store
Binary file not shown.
Empty file modified lang/00_object.rb
100644 → 100755
Empty file.
Empty file modified lang/README.md
100644 → 100755
Empty file.
26 changes: 26 additions & 0 deletions lang/accessors.rb
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 added lang/arrays/concatenate.rb
Empty file.
10 changes: 10 additions & 0 deletions lang/arrays/create.rb
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 added lang/arrays/enumerator.rb
Empty file.
Empty file added lang/arrays/iterator.rb
Empty file.
58 changes: 58 additions & 0 deletions lang/class.rb
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 modified lang/class/accessors.rb
100644 → 100755
Empty file.
58 changes: 58 additions & 0 deletions lang/class/class.rb
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 modified lang/class/classes_dinamicas.rb
100644 → 100755
Empty file.
Empty file modified lang/class/estrutura.rb
100644 → 100755
Empty file.
Empty file modified lang/class/inheritance.rb
100644 → 100755
Empty file.
Empty file modified lang/class/method_lockup.rb
100644 → 100755
Empty file.
Empty file modified lang/class/open_classes.rb
100644 → 100755
Empty file.
Empty file modified lang/class/variavel_class.rb
100644 → 100755
Empty file.
Empty file modified lang/class/variavel_instance.rb
100644 → 100755
Empty file.
Empty file modified lang/comments.rb
100644 → 100755
Empty file.
33 changes: 33 additions & 0 deletions lang/control_structure/if.rb
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 modified lang/conventions.rb
100644 → 100755
Empty file.
15 changes: 15 additions & 0 deletions lang/datatypes/array/create.rb
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 added lang/datatypes/array/methods.rb
Empty file.
Empty file modified lang/datatypes/bignum.rb
100644 → 100755
Empty file.
Empty file modified lang/datatypes/constantes.rb
100644 → 100755
Empty file.
Empty file modified lang/datatypes/false_class.rb
100644 → 100755
Empty file.
Empty file modified lang/datatypes/fixnum.rb
100644 → 100755
Empty file.
Empty file modified lang/datatypes/float.rb
100644 → 100755
Empty file.
18 changes: 18 additions & 0 deletions lang/datatypes/hash/create.rb
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]
13 changes: 13 additions & 0 deletions lang/datatypes/hash/hash.rb
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]
18 changes: 18 additions & 0 deletions lang/datatypes/hash/try_convert.rb
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 modified lang/datatypes/nil_class.rb
100644 → 100755
Empty file.
Empty file modified lang/datatypes/proc.rb
100644 → 100755
Empty file.
Empty file modified lang/datatypes/range.rb
100644 → 100755
Empty file.
Empty file modified lang/datatypes/simbol.rb
100644 → 100755
Empty file.
Empty file modified lang/datatypes/string/create.rb
100644 → 100755
Empty file.
Empty file modified lang/datatypes/string/embedded.rb
100644 → 100755
Empty file.
Empty file modified lang/datatypes/string/encoding.rb
100644 → 100755
Empty file.
Empty file modified lang/datatypes/string/heredoc.rb
100644 → 100755
Empty file.
Empty file modified lang/datatypes/string/methods.rb
100644 → 100755
Empty file.
Empty file modified lang/datatypes/string/object.rb
100644 → 100755
Empty file.
Empty file modified lang/datatypes/true_class.rb
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions lang/date.rb
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 modified lang/er/regex.rb
100644 → 100755
Empty file.
Empty file modified lang/estrutura_controle/begin_end.rb
100644 → 100755
Empty file.
Empty file modified lang/estrutura_controle/case.rb
100644 → 100755
Empty file.
Empty file modified lang/estrutura_controle/for.rb
100644 → 100755
Empty file.
Empty file modified lang/estrutura_controle/if.rb
100644 → 100755
Empty file.
Empty file modified lang/estrutura_controle/unless.rb
100644 → 100755
Empty file.
Empty file modified lang/estrutura_controle/until.rb
100644 → 100755
Empty file.
Empty file modified lang/estrutura_controle/while.rb
100644 → 100755
Empty file.
Empty file modified lang/estrutura_dados/array/definicao.rb
100644 → 100755
Empty file.
Empty file modified lang/estrutura_dados/array/methods.rb
100644 → 100755
Empty file.
Empty file modified lang/estrutura_dados/hash/definicao.rb
100644 → 100755
Empty file.
Empty file modified lang/estrutura_dados/hash/methods.rb
100644 → 100755
Empty file.
Empty file modified lang/estrutura_dados/hash/try_convert.rb
100644 → 100755
Empty file.
Empty file modified lang/estrutura_dados/introducao.rb
100644 → 100755
Empty file.
Empty file modified lang/estrutura_dados/set.rb
100644 → 100755
Empty file.
Empty file modified lang/fiber.rb
100644 → 100755
Empty file.
Empty file modified lang/file.rb
100644 → 100755
Empty file.
Empty file modified lang/include_file.rb
100644 → 100755
Empty file.
Empty file modified lang/inferencia_tipo.rb
100644 → 100755
Empty file.
21 changes: 21 additions & 0 deletions lang/inheritance.rb
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 added lang/interpolacao_expressoes.rb
Empty file.
Empty file modified lang/introducao.rb
100644 → 100755
Empty file.
Empty file modified lang/json.rb
100644 → 100755
Empty file.
Empty file modified lang/method_lockup.rb
100644 → 100755
Empty file.
Empty file modified lang/methods/arg_obrigatorios.rb
100644 → 100755
Empty file.
Empty file modified lang/methods/arg_opcionais.rb
100644 → 100755
Empty file.
Empty file modified lang/methods/arg_valor_padrao.rb
100644 → 100755
Empty file.
Empty file modified lang/methods/blocos_parametros.rb
100644 → 100755
Empty file.
11 changes: 11 additions & 0 deletions lang/methods/create.rb
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 modified lang/methods/definicao.rb
100644 → 100755
Empty file.
Empty file modified lang/methods/metodos_destrutivos.rb
100644 → 100755
Empty file.
Empty file modified lang/methods/metodos_predicados.rb
100644 → 100755
Empty file.
Empty file modified lang/methods/parameters.rb
100644 → 100755
Empty file.
Empty file modified lang/module.rb
100644 → 100755
Empty file.
Empty file modified lang/multilingualization.rb
100644 → 100755
Empty file.
22 changes: 22 additions & 0 deletions lang/object.rb
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 modified lang/operadores.rb
100644 → 100755
Empty file.
Empty file modified lang/standard_library/date.rb
100644 → 100755
Empty file.
Empty file modified lang/threads.rb
100644 → 100755
Empty file.
Empty file modified lang/tipagem_dinamica.rb
100644 → 100755
Empty file.
Empty file modified lang/tipagem_forte.rb
100644 → 100755
Empty file.
32 changes: 32 additions & 0 deletions lang/variables/class.rb
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 modified lang/variables/convencoes.rb
100644 → 100755
Empty file.
Empty file modified lang/variables/global.rb
100644 → 100755
Empty file.
28 changes: 28 additions & 0 deletions lang/variables/instance.rb
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
5 changes: 5 additions & 0 deletions lang/variables/intro.rb
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 modified lang/variables/local.rb
100644 → 100755
Empty file.
Empty file modified lang/variables/pseudo.rb
100644 → 100755
Empty file.
Empty file modified metaprogramming/01_self_receiver.rb
100644 → 100755
Empty file.
Empty file modified metaprogramming/02_singleton_class.rb
100644 → 100755
Empty file.
Empty file modified metaprogramming/03_variavel_instancia_class.rb
100644 → 100755
Empty file.
Empty file modified metaprogramming/04_classes_dinamicas.rb
100644 → 100755
Empty file.

0 comments on commit de8954a

Please sign in to comment.