File.open('proruby.jpg') RUBY_VERSION def que_es obj obj ? "#{obj} es true" : "#{obj} es false" end que_es [] que_es 1 que_es false s = "Cactus" s[0] = 'KKKK' s "hola".to_i ".5".to_f " 1.5 - fffffff ".to_f "..... 1.54 - fffffff ".to_f a = [] a[4] = 1 a a[10] arr = Array.new(3, {}) arr[1][:a] = 1 arr array = [1, 2, 3, 4, 100] array * 2 array * '|' [1, [2,3], 4, [[[5]]]] * ',' h = {} h[1] = "a" h[2] = "b" h[3] = "c" h.delete(1) h[1] = "A" h.keys a = [] h = {a => 2} h.default = 'defecto' a << 1 h h[a] h.rehash h[a] key = 'a' hash = {key => 1} key.upcase! hash key.object_id hash.keys[0].object_id {:a => 1, :b => 2} {a: 1, b: 2} :simbolo :"Con espacios" "hola".object_id "hola".object_id :hola.object_id :hola.object_id (1..4).to_a (1...4).to_a e = "a".."z" e.to_enum.next.next def llama_bloque puts "inicio llama_bloque" yield puts "fin llama_bloque" end llama_bloque { puts "en el bloque" } def llama_bloque puts "inicio llama_bloque" yield 2 puts "fin llama_bloque" end llama_bloque { |x| puts "en el bloque #{x}" } def masticar numeros for x in numeros yield x * 2 end end masticar [1,2,3,4] { |y| y / 2 } "hola".chop "hola".chomp "hola\n".chomp [1, 2, 3].map {|x| x * 2} [1, 2, 3].collect do |x| n = 1 + 1 x * n end array = ['hola', 3, Object.new] array.size array.count array.length array[10] = 1 array [array.size, array.count, array.length] [1.to_s, "5".to_i] "1".to_int class MyInt def to_int 0 end end [1, 2][MyInt.new] ['un', 'dos', 'tres'].map(&:upcase) class Symbol def to_proc Proc.new {|x| x * 2} end end ['un', 'dos', 'tres'].map(&:upcase) def come_bloques a puts a yield end come_bloques 1 { puts 2} come_bloques(1) { puts 2} come_bloques 1 do puts 2 end q.nil? q = 1 if q.nil? if false f = 1 end f.inspect def parametros a, b=a*2 [a, b] end parametros 10 def ejemplo(a, *b, c) puts [a, b, c] end ejemplo 1, 2, 3, 4, 5 a = 1 if true if true puts "no no no no" end if false config = { A1: 1, B2: 2 } A1 = 1, B2 = 2 A1 C1 = 'A' C2 = 'B' C1 + C2 'A' +C2 C1 +C2 def C(*args) [:C, *args]; end C = 99 C +1 C + 1