0
- irb> $/ # The $/ is the line separator, it is normally set to \n, which represents _Enter_
0
- => "\n" # or "end of line". The slash represents a sword slashing lines in a file.
0
- # The line separator controls how methods like each_line or readlines breaks up strings.
0
- irb> "Jeff,Jerry,Jill\nMichael,Mary,Myrtle".each_line { |names| p names }
0
- => "Jeff,Jerry,Jill\n"
0
- => "Michael,Mary,Myrtle"
0
- # If you change the line separator, you change how many methods work, such as each_line.
0
- # See what happens when I change the line separator to a comma.
0
- irb> "Jeff,Jerry,Jill\nMichael,Mary,Myrtle".each_line { |names| p names }
0
- irb> $, # The $, variable is the join separator, used when joining strings with
0
- => nil # Array#join or Kernel::print. The comma is a common join character.
0
- # The join separator is normally empty.
0
- irb> ['candle', 'soup', 'mackarel'].join
0
- => "candlesoupmackarel"
0
- irb> $, = ' * '; ['candle', 'soup', 'mackarel'].join
0
- => "candle * soup * mackarel"
0
- # But, usually, you won't need the global variable.
0
- irb> ['candle', 'soup', 'mackarel'].join ' # '
0
- => "candle # soup # mackarel"
0
- irb> $; # The $; variable is the split separator, used when splitting strings
0
- => nil # with String#split.
0
- # The split separator is normally empty, which means String#split will separate
0
- # the string where there is whitespace.
0
- irb> "candle soup\nmackarel".split
0
- => ["candle", "soup", "mackarel"]
0
- irb> $; = 'a'; "candle soup\nmackarel".split
0
- => ["c", "ndle soup\nm", "ck", "rel"]
0
- # But, usually, you won't need the global variable.
0
- irb> "candle # soup # mackarel".split ' # '
0
- => ['candle', 'soup', 'mackarel']
0
- Outside the _Gorilla Mint_, Blix scolded the foxes. "We could have used that guy's help! If he knows
0
- where R.K. is, we could use his cunning!"
0
- "*We don't need that ape's money!*" said Fox Small. "*We can make our _own_ money!*"
0
- "*We could support electronic wristbands!*" said Fox Tall.
0
- "His money is worthless," said Blix. "It's gorilla money. It has no value. It's worse than
0
- "But it serves a purpose," said Fox Tall.
0
- "No it doesn't," said Fox Small. "He just said it's worthless."
0
- "But what about linoleum and surgeries?" said Fox Tall.
0
- "Yeah," said Fox Small, up at Blix. "What about linoleum and surgeries?"
0
- "If all the hospitals were staffed by gorillas and all the home improvement chains were strictly operated
0
- by gorillas, then -- YES -- you could buy linoleum and surgeries. But I _guarantee_ that you would have
0
- very sloppy linoleum and very hideous surgeries. I don't think you'd make it out of that economy alive."
0
- "So, if R.K. is so cunning," said Fox Tall, grinning slyly, "why does he print such worthless currency?"
0
- "It's a cover for other activities," said Blix. "Besides, if you're so smart, why did you resort to
0
- violently pounding that poor gorilla?"
0
- "I guess that was a bad play," said Fox Tall, hanging his head. "My friend here will tell you that I've
0
- been on edge all day."
0
- "And your rage finally reared its fuming snout!" said Fox Small. "You're finally living up to your
0
- Down the lanes they travelled, the two foxes oblivious to their direction, but having a good time
0
- now that they had Blix leading the way with such urgency. They lapsed into a careless wandering right behind Blix
0
- and spent their afternoon heckling most of the passersby.
0
- One such target of their ongoing commentary was The Winged Scroll Carriers, pairs of bats that carry
0
- documents which need to be immediately sworn and notarized. There can be no delay, they must go swift,
0
- there is not even time to roll up the scroll, no, they must drop their swiss cheese and be out the door.
0
- These couriers resemble a kind of Ruby construct called *delimited types*. A long series of characters
0
- comprises the scroll, flanked on each side by a bat bracing its curly wings to hold the scroll together.
0
- The opening bat wears a hat on which is written @%w@, which identifies the scroll as a set of words.
0
- irb> bats = %w{The Winged Scroll Carriers}
0
- => ['The', 'Winged', 'Scroll', 'Carriers']
0
- The @%w@ bats and their scroll, when fed into Ruby, emerge as an array of words. This syntax is a shortcut
0
- in case you don't want to go through the trouble of decorating each word with commas and quotes. You are
0
- in a hurry, too, there can be no delay. You jot out the words between the bats and let Ruby figure out where
0
- Other bats, other hats. For instance, the @%x@ hat runs an external program.
0
+ irb> $/ # O $/ é a linha separadora, ele é normalmente configurado para \n, o qual representa o _Enter_
0
+ => "\n" # ou "o final da linha". A barra representa uma espada que corta e reduz linhas em um arquivo.
0
+ # A linha separadora controla como os métodos each_line ou readlines quebram as strings.
0
+ irb> "Jeff,Jerry,Jill\nMichael,Mary,Myrtle".each_line { |nomes| p nomes }
0
+ => "Jeff,Jerry,Jill\n"
0
+ => "Michael,Mary,Myrtle"
0
+ # Se você mudar a linha separadora, você muda como os métodos trabalham, tal como o each_line.
0
+ # Veja o que acontece quando eu mudar a linha separadora por uma vírgula.
0
+ irb> "Jeff,Jerry,Jill\nMichael,Mary,Myrtle".each_line { |nomes| p nomes }
0
+ irb> $, # O $, é a variável que une o separador, usado ao unir strings com
0
+ => nil # Array#join or Kernel::print. A vírgula é um caractere comum de junção.
0
+ # O separador de junção está normalmente vazio.
0
+ irb> ['vela', 'sopa', 'mackarel'].join
0
+ irb> $, = ' * '; ['vela', 'sopa', 'mackarel'].join
0
+ => "vela * sopa * mackarel"
0
+ # Mas, geralmente, você não necessitará de uma variável global.
0
+ irb> ['vela', 'sopa', 'mackarel'].join ' # '
0
+ => "vela # sopa # mackarel"
0
+ irb> $; # O $; a variável é o separador que divide, usado ao dividir strings
0
+ => nil # com String#split.
0
+ # O separador split está normalmente vazio, que significa que String#split separará
0
+ # a string onde há um espaço em branco.
0
+ irb> "vela sopa\nmackarel".split
0
+ => ["vela", "sopa", "mackarel"]
0
+ irb> $; = 'a'; "vela sopa\nmackarel".split
0
+ => ["vel", "sop", "\nm", "ck", "rel"]
0
+ # Mas, geralmente, você não necessitará de uma variável global.
0
+ irb> "vela # sopa # mackarel".split ' # '
0
+ => ['vela', 'sopa', 'mackarel']
0
+ Fora do _Casa da Moeda do Gorila_, Blix repreendeu as raposas. "Nós poderíamos ter aproveitado a ajuda desse cara'! Se sabe
0
+ onde está R.K., nós poderíamos usar a astúcia dele!"
0
+ "*Nós não precisamos do dinheiro do macaco!*" disse a Raposa Pequena. "*We podemos criar nosso _próprio_ dinheiro!*"
0
+ "*Nós podemos suportar pulseiras eletrônicas!*" disse a Raposa Alta.
0
+ "Seu dinheiro é sem valor," disse Blix. "O dinheiro é do gorila. Não tem valor. Ele é pior do que
0
+ "Mas serve pra uma finalidade," disse a Raposa Alta.
0
+ "Não ele não serve," disse a Raposa Pequena. "Ele apenas disse que o dinheiro não tem importância."
0
+ "Mas sobre o tapete impermeável e as cirurgias?" disse a Raposa Alta.
0
+ "Sim," disse a Raposa Pequena para Blix. "O que dizer do tapete impermeável e as cirurgias?"
0
+ "Se todos os hospitais possuem uma equipe de gorila e toda as casas receberam uma rede de melhorias estritamente operadas
0
+ por gorila, então -- SIM -- você poderia comprar o tapete impermeável e as cirurgias. Mas Eu _garanto_ que você teria
0
+ um tapete impermeável desleixado e muito cirurgias horríveis. Eu não acho que você tinha que torná-lo do que uma economia com vida."
0
+ "Assim, se R.K. é tão esperto," disse a Raposa Alta, dando risada dissimuladamente, "por que imprime tal moeda sem valor?"
0
+ "Ele é a tampa para outras atividades," disse Blix. "Além do que, se você é tão esperto, porque você recorreu
0
+ violentamente derrotando aquele pobre gorila?"
0
+ "Eu suponho que foi um mau jogo," disse a Raposa Alta, pendendo sua cabeça. "Meu amigo direi a você que eu fiquei
0
+ de saco cheio o dia inteiro."
0
+ "E sua raiva finalmente levantou seu focinho fumegante!" disse a Raposa Pequena. "Você finalmente está vivendo a vida à altura do seu
0
+ Abaixo das pistas que eles viajaram, as duas raposas distraídas no seu rumo, mas tendo um bom tempo
0
+ agora que tiveram Blix conduzindo o caminho com tanta urgência. Eles passaram o tempo desatentamente perambularam a direita atrás de Blix
0
+ e perdendo sua tarde importunando a maioria dos pedestres.
0
+ Um dos alvo dos seus permanentes comentário era Os Transportadores Alados de rolo de papel, pares de morcegos que carregam
0
+ documentos que precisam de ser imediatamente autenticados. Não pode haver nenhum atraso, eles devem ir rápido,
0
+ não há mesmo uma hora para enrolar o rolo de papel, não, eles devem deixar cair seus queijos suíço e ir para fora da porta.
0
+ Estes correios assemelham-se a um tipo de construção do Ruby chamado *tipos delimitados*. Uma série longa de caracteres
0
+ compreende o rolo de papel, em cada lado por um morcego estimulante que segura suas asas balançam para manter o rolo de papel unido.
0
+ O morcego da ponto usa um chapéu em que está escrito @%w@, que identifica o rolo de papel como um conjunto de palavras.
0
+ irb> bats = %w{Os Transportadores Alados de Rolo de Papel}
0
+ => ['Os', 'Transportadores', 'Alados', 'de', 'Rolo', 'de', 'Papel']
0
+ Os morcegos de @%w@ e seus rolo de papel, quando alimentados dentro do Ruby, emergem como um array de palavras. Esta sintaxe é um atalho
0
+ caso que você não queira atravessar o problema de decorar cada palavra com vírgulas e citações. Você está
0
+ com pressa, também, não pode haver nenhum atraso. Você anota fora as palavras entre os morcegos e deixa o rubi calcular fora onde
0
+ Outros morcegos, outros chapéus. Por exemplo, o chapéu de @%x@ funciona um programa externo.
Comments
No one has commented yet.