diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/Vagrantfile b/Vagrantfile old mode 100644 new mode 100755 diff --git a/book_store/lib/biblioteca.rb b/book_store/lib/biblioteca.rb old mode 100644 new mode 100755 diff --git a/book_store/lib/livro.rb b/book_store/lib/livro.rb old mode 100644 new mode 100755 diff --git a/book_store/lib/loja_virtual.rb b/book_store/lib/loja_virtual.rb old mode 100644 new mode 100755 diff --git a/book_store/lib/relatorio.rb b/book_store/lib/relatorio.rb old mode 100644 new mode 100755 diff --git a/lang/.DS_Store b/lang/.DS_Store index a57d86f..889dee1 100755 Binary files a/lang/.DS_Store and b/lang/.DS_Store differ diff --git a/lang/00_object.rb b/lang/00_object.rb old mode 100644 new mode 100755 diff --git a/lang/README.md b/lang/README.md old mode 100644 new mode 100755 diff --git a/lang/accessors.rb b/lang/accessors.rb new file mode 100755 index 0000000..61e47b1 --- /dev/null +++ b/lang/accessors.rb @@ -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 \ No newline at end of file diff --git a/lang/arrays/concatenate.rb b/lang/arrays/concatenate.rb new file mode 100755 index 0000000..e69de29 diff --git a/lang/arrays/create.rb b/lang/arrays/create.rb new file mode 100755 index 0000000..feb6f23 --- /dev/null +++ b/lang/arrays/create.rb @@ -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; + diff --git a/lang/arrays/enumerator.rb b/lang/arrays/enumerator.rb new file mode 100755 index 0000000..e69de29 diff --git a/lang/arrays/iterator.rb b/lang/arrays/iterator.rb new file mode 100755 index 0000000..e69de29 diff --git a/lang/class.rb b/lang/class.rb new file mode 100755 index 0000000..476eee1 --- /dev/null +++ b/lang/class.rb @@ -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 diff --git a/lang/class/accessors.rb b/lang/class/accessors.rb old mode 100644 new mode 100755 diff --git a/lang/class/class.rb b/lang/class/class.rb new file mode 100755 index 0000000..476eee1 --- /dev/null +++ b/lang/class/class.rb @@ -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 diff --git a/lang/class/classes_dinamicas.rb b/lang/class/classes_dinamicas.rb old mode 100644 new mode 100755 diff --git a/lang/class/estrutura.rb b/lang/class/estrutura.rb old mode 100644 new mode 100755 diff --git a/lang/class/inheritance.rb b/lang/class/inheritance.rb old mode 100644 new mode 100755 diff --git a/lang/class/method_lockup.rb b/lang/class/method_lockup.rb old mode 100644 new mode 100755 diff --git a/lang/class/open_classes.rb b/lang/class/open_classes.rb old mode 100644 new mode 100755 diff --git a/lang/class/variavel_class.rb b/lang/class/variavel_class.rb old mode 100644 new mode 100755 diff --git a/lang/class/variavel_instance.rb b/lang/class/variavel_instance.rb old mode 100644 new mode 100755 diff --git a/lang/comments.rb b/lang/comments.rb old mode 100644 new mode 100755 diff --git a/lang/control_structure/if.rb b/lang/control_structure/if.rb new file mode 100755 index 0000000..0cad3aa --- /dev/null +++ b/lang/control_structure/if.rb @@ -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 \ No newline at end of file diff --git a/lang/conventions.rb b/lang/conventions.rb old mode 100644 new mode 100755 diff --git a/lang/datatypes/array/create.rb b/lang/datatypes/array/create.rb new file mode 100755 index 0000000..bd343d7 --- /dev/null +++ b/lang/datatypes/array/create.rb @@ -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 } diff --git a/lang/datatypes/array/methods.rb b/lang/datatypes/array/methods.rb new file mode 100755 index 0000000..e69de29 diff --git a/lang/datatypes/bignum.rb b/lang/datatypes/bignum.rb old mode 100644 new mode 100755 diff --git a/lang/datatypes/constantes.rb b/lang/datatypes/constantes.rb old mode 100644 new mode 100755 diff --git a/lang/datatypes/false_class.rb b/lang/datatypes/false_class.rb old mode 100644 new mode 100755 diff --git a/lang/datatypes/fixnum.rb b/lang/datatypes/fixnum.rb old mode 100644 new mode 100755 diff --git a/lang/datatypes/float.rb b/lang/datatypes/float.rb old mode 100644 new mode 100755 diff --git a/lang/datatypes/hash/create.rb b/lang/datatypes/hash/create.rb new file mode 100755 index 0000000..bdbae3a --- /dev/null +++ b/lang/datatypes/hash/create.rb @@ -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] diff --git a/lang/datatypes/hash/hash.rb b/lang/datatypes/hash/hash.rb new file mode 100755 index 0000000..ba07473 --- /dev/null +++ b/lang/datatypes/hash/hash.rb @@ -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] \ No newline at end of file diff --git a/lang/datatypes/hash/try_convert.rb b/lang/datatypes/hash/try_convert.rb new file mode 100755 index 0000000..395ad03 --- /dev/null +++ b/lang/datatypes/hash/try_convert.rb @@ -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) \ No newline at end of file diff --git a/lang/datatypes/nil_class.rb b/lang/datatypes/nil_class.rb old mode 100644 new mode 100755 diff --git a/lang/datatypes/proc.rb b/lang/datatypes/proc.rb old mode 100644 new mode 100755 diff --git a/lang/datatypes/range.rb b/lang/datatypes/range.rb old mode 100644 new mode 100755 diff --git a/lang/datatypes/simbol.rb b/lang/datatypes/simbol.rb old mode 100644 new mode 100755 diff --git a/lang/datatypes/string/create.rb b/lang/datatypes/string/create.rb old mode 100644 new mode 100755 diff --git a/lang/datatypes/string/embedded.rb b/lang/datatypes/string/embedded.rb old mode 100644 new mode 100755 diff --git a/lang/datatypes/string/encoding.rb b/lang/datatypes/string/encoding.rb old mode 100644 new mode 100755 diff --git a/lang/datatypes/string/heredoc.rb b/lang/datatypes/string/heredoc.rb old mode 100644 new mode 100755 diff --git a/lang/datatypes/string/methods.rb b/lang/datatypes/string/methods.rb old mode 100644 new mode 100755 diff --git a/lang/datatypes/string/object.rb b/lang/datatypes/string/object.rb old mode 100644 new mode 100755 diff --git a/lang/datatypes/true_class.rb b/lang/datatypes/true_class.rb old mode 100644 new mode 100755 diff --git a/lang/date.rb b/lang/date.rb new file mode 100755 index 0000000..d54c139 --- /dev/null +++ b/lang/date.rb @@ -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? \ No newline at end of file diff --git a/lang/er/regex.rb b/lang/er/regex.rb old mode 100644 new mode 100755 diff --git a/lang/estrutura_controle/begin_end.rb b/lang/estrutura_controle/begin_end.rb old mode 100644 new mode 100755 diff --git a/lang/estrutura_controle/case.rb b/lang/estrutura_controle/case.rb old mode 100644 new mode 100755 diff --git a/lang/estrutura_controle/for.rb b/lang/estrutura_controle/for.rb old mode 100644 new mode 100755 diff --git a/lang/estrutura_controle/if.rb b/lang/estrutura_controle/if.rb old mode 100644 new mode 100755 diff --git a/lang/estrutura_controle/unless.rb b/lang/estrutura_controle/unless.rb old mode 100644 new mode 100755 diff --git a/lang/estrutura_controle/until.rb b/lang/estrutura_controle/until.rb old mode 100644 new mode 100755 diff --git a/lang/estrutura_controle/while.rb b/lang/estrutura_controle/while.rb old mode 100644 new mode 100755 diff --git a/lang/estrutura_dados/array/definicao.rb b/lang/estrutura_dados/array/definicao.rb old mode 100644 new mode 100755 diff --git a/lang/estrutura_dados/array/methods.rb b/lang/estrutura_dados/array/methods.rb old mode 100644 new mode 100755 diff --git a/lang/estrutura_dados/hash/definicao.rb b/lang/estrutura_dados/hash/definicao.rb old mode 100644 new mode 100755 diff --git a/lang/estrutura_dados/hash/methods.rb b/lang/estrutura_dados/hash/methods.rb old mode 100644 new mode 100755 diff --git a/lang/estrutura_dados/hash/try_convert.rb b/lang/estrutura_dados/hash/try_convert.rb old mode 100644 new mode 100755 diff --git a/lang/estrutura_dados/introducao.rb b/lang/estrutura_dados/introducao.rb old mode 100644 new mode 100755 diff --git a/lang/estrutura_dados/set.rb b/lang/estrutura_dados/set.rb old mode 100644 new mode 100755 diff --git a/lang/fiber.rb b/lang/fiber.rb old mode 100644 new mode 100755 diff --git a/lang/file.rb b/lang/file.rb old mode 100644 new mode 100755 diff --git a/lang/include_file.rb b/lang/include_file.rb old mode 100644 new mode 100755 diff --git a/lang/inferencia_tipo.rb b/lang/inferencia_tipo.rb old mode 100644 new mode 100755 diff --git a/lang/inheritance.rb b/lang/inheritance.rb new file mode 100755 index 0000000..03196f4 --- /dev/null +++ b/lang/inheritance.rb @@ -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 \ No newline at end of file diff --git a/lang/interpolacao_expressoes.rb b/lang/interpolacao_expressoes.rb new file mode 100755 index 0000000..e69de29 diff --git a/lang/introducao.rb b/lang/introducao.rb old mode 100644 new mode 100755 diff --git a/lang/json.rb b/lang/json.rb old mode 100644 new mode 100755 diff --git a/lang/method_lockup.rb b/lang/method_lockup.rb old mode 100644 new mode 100755 diff --git a/lang/methods/arg_obrigatorios.rb b/lang/methods/arg_obrigatorios.rb old mode 100644 new mode 100755 diff --git a/lang/methods/arg_opcionais.rb b/lang/methods/arg_opcionais.rb old mode 100644 new mode 100755 diff --git a/lang/methods/arg_valor_padrao.rb b/lang/methods/arg_valor_padrao.rb old mode 100644 new mode 100755 diff --git a/lang/methods/blocos_parametros.rb b/lang/methods/blocos_parametros.rb old mode 100644 new mode 100755 diff --git a/lang/methods/create.rb b/lang/methods/create.rb new file mode 100755 index 0000000..a0ed60d --- /dev/null +++ b/lang/methods/create.rb @@ -0,0 +1,11 @@ +def saysomething() + puts "Hello" +end +saysomething + + +def saysomething + puts "Hello" +end +saysomething + diff --git a/lang/methods/definicao.rb b/lang/methods/definicao.rb old mode 100644 new mode 100755 diff --git a/lang/methods/metodos_destrutivos.rb b/lang/methods/metodos_destrutivos.rb old mode 100644 new mode 100755 diff --git a/lang/methods/metodos_predicados.rb b/lang/methods/metodos_predicados.rb old mode 100644 new mode 100755 diff --git a/lang/methods/parameters.rb b/lang/methods/parameters.rb old mode 100644 new mode 100755 diff --git a/lang/module.rb b/lang/module.rb old mode 100644 new mode 100755 diff --git a/lang/multilingualization.rb b/lang/multilingualization.rb old mode 100644 new mode 100755 diff --git a/lang/object.rb b/lang/object.rb new file mode 100755 index 0000000..76623cc --- /dev/null +++ b/lang/object.rb @@ -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 + diff --git a/lang/operadores.rb b/lang/operadores.rb old mode 100644 new mode 100755 diff --git a/lang/standard_library/date.rb b/lang/standard_library/date.rb old mode 100644 new mode 100755 diff --git a/lang/threads.rb b/lang/threads.rb old mode 100644 new mode 100755 diff --git a/lang/tipagem_dinamica.rb b/lang/tipagem_dinamica.rb old mode 100644 new mode 100755 diff --git a/lang/tipagem_forte.rb b/lang/tipagem_forte.rb old mode 100644 new mode 100755 diff --git a/lang/variables/class.rb b/lang/variables/class.rb new file mode 100755 index 0000000..746472f --- /dev/null +++ b/lang/variables/class.rb @@ -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 \ No newline at end of file diff --git a/lang/variables/convencoes.rb b/lang/variables/convencoes.rb old mode 100644 new mode 100755 diff --git a/lang/variables/global.rb b/lang/variables/global.rb old mode 100644 new mode 100755 diff --git a/lang/variables/instance.rb b/lang/variables/instance.rb new file mode 100755 index 0000000..e8bb20d --- /dev/null +++ b/lang/variables/instance.rb @@ -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 diff --git a/lang/variables/intro.rb b/lang/variables/intro.rb new file mode 100755 index 0000000..850584a --- /dev/null +++ b/lang/variables/intro.rb @@ -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}" diff --git a/lang/variables/local.rb b/lang/variables/local.rb old mode 100644 new mode 100755 diff --git a/lang/variables/pseudo.rb b/lang/variables/pseudo.rb old mode 100644 new mode 100755 diff --git a/metaprogramming/01_self_receiver.rb b/metaprogramming/01_self_receiver.rb old mode 100644 new mode 100755 diff --git a/metaprogramming/02_singleton_class.rb b/metaprogramming/02_singleton_class.rb old mode 100644 new mode 100755 diff --git a/metaprogramming/03_variavel_instancia_class.rb b/metaprogramming/03_variavel_instancia_class.rb old mode 100644 new mode 100755 diff --git a/metaprogramming/04_classes_dinamicas.rb b/metaprogramming/04_classes_dinamicas.rb old mode 100644 new mode 100755