diff --git a/README.md b/README.md index 690c20bd..edf7e6fe 100644 --- a/README.md +++ b/README.md @@ -5,18 +5,31 @@ where you can learn the Ruby language. Starting from zero knowledge about programming you can learn the basics of Ruby in 56 short lessons. ## Credits -Try Ruby version 1 by _why the lucky stiff_ -Try Ruby version 2 by _Andrew McElroy & David Miani_ -Try Ruby version 3 by _Eric Allam & Nick Walsh_ -Try Ruby version 4 by _Ivo Herweijer_ +Try Ruby version 1 by _why the lucky stiff_ +Try Ruby version 2 by _Andrew McElroy & David Miani_ +Try Ruby version 3 by _Eric Allam & Nick Walsh_ +Try Ruby version 4 by _Ivo Herweijer_ This website is partially based on OpalRb.com by _Adam Beynon_. ### Translations -Spanish translation by _Jesus Gabriel y Galan_ & _Pablo García_ -Dutch translation by _Ivo Herweijer_ +Spanish translation by _Jesus Gabriel y Galan_ & _Pablo García_ +Dutch translation by _Ivo Herweijer_ Brazilian Portuguese translation by [_Ricardo da Verdade Silva_](https://github.com/ricardovsilva)
Japanese translation by _Koji Shimada_ & _Masayoshi Takahashi_ +French translation by _Olivier Lacan_ + +To add a translation: +- duplicate the `translations/en` directory and name the new directory + with the appropriate [ISO 639-1 code][iso] for the language new + language. +- translate all Markdown files within your new translation directory. +- duplicate `source/try_ruby_en.json`, replace `en` with your new + language code, and translate all lesson titles inside the file. +- add a reference to your Markdown translation directory and JSON file + inside of `collector.rb` so that they can be loaded. +- submit a Pull Request with a branch named after your translation + language. ## Preparing Clone this repo, and use bundler to get dependencies: @@ -71,3 +84,5 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +[iso]: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes diff --git a/collector.rb b/collector.rb index c76710cb..7bf79781 100644 --- a/collector.rb +++ b/collector.rb @@ -45,7 +45,7 @@ def source_is_newer? def collect_sources return if @sources.empty? - + #@markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, extensions = {}) @markdown = Redcarpet::Markdown.new(HTMLWithPants, extensions = {}) @@ -138,6 +138,7 @@ def initialize(app, options_hash={}, &block) Collector.new('translations/es/try_ruby_*.md', 'source/try_ruby_es.json').collect Collector.new('translations/pt-br/try_ruby_*.md', 'source/try_ruby_pt-br.json').collect Collector.new('translations/ja/try_ruby_*.md', 'source/try_ruby_ja.json').collect + Collector.new('translations/fr/try_ruby_*.md', 'source/try_ruby_fr.json').collect # TODO: add any new translations here diff --git a/source/articles/2015-01-01-try-ruby-version-4.html.markdown b/source/articles/2015-01-01-try-ruby-version-4.html.markdown index ce06736e..2578ef3c 100644 --- a/source/articles/2015-01-01-try-ruby-version-4.html.markdown +++ b/source/articles/2015-01-01-try-ruby-version-4.html.markdown @@ -12,11 +12,11 @@ the lucky stiff', a.k.a. \_Why. You can read more about him on Wikipedia. \_Why doesn't exist anymore, but TryRuby lives on. It was first recreated by Andrew McElroy -and David Miani. Next Eric Allam and Nick Walsh took over (Codeschool/EnvyLabs, +and David Miani. Next Eric Allam and Nick Walsh took over (Envy Labs/Code School, available via TryRuby.org). ### Why_ -This fourth iteration of TryRuby was created for several reasons. +This fourth iteration of TryRuby was created for several reasons. - The lesson content was getting a bit dated. For instance the stuff about reading and writing disk files does not really belong in an entry level course these days. Writing blog software @@ -24,7 +24,7 @@ This fourth iteration of TryRuby was created for several reasons. - Lesson content also missed some important information (like __if__ statements) - All previous TryRuby versions consisted of an irb interpreter with a web front-end. Even though some security measures have been taken (isolating and restricting the irb process - and whitelisting input), this still sounds like a bad idea from a security perspective! + and whitelisting input), this still sounds like a bad idea from a security perspective! TryRubyR4 runs inside the web browser ### Changes @@ -39,7 +39,7 @@ I had to make some alterations to the TryRuby lesson content. Also updated some - Removed mousehole stuff - Improved the feedback given to the user based on the program's output a bit - Added support for lesson content in multiple languages. The Spanish, Brazilian Portuguese, - Japanese and Dutch translations are available. + Japanese and Dutch translations are available. __If YOU would like to add a translation to TryRuby you are most welcome !__ - Added explanation of if/else statements - Changed the subject of the "Class" tutorials from building a blog (so last decade) to making an diff --git a/source/index.html.markdown b/source/index.html.markdown index f229022d..4d37992f 100644 --- a/source/index.html.markdown +++ b/source/index.html.markdown @@ -8,17 +8,18 @@ description: Learn to program in Ruby in 30 minutes
-
- +
+
-
+
@@ -26,7 +27,7 @@ description: Learn to program in Ruby in 30 minutes
- +

Got 30 minutes? Give Ruby a shot right now!

@@ -35,7 +36,7 @@ description: Learn to program in Ruby in 30 minutes

Ruby is a programming language from Japan which is revolutionizing software development.

The beauty of Ruby is found in its balance between simplicity and power.

You can type some Ruby code in the editor and use these buttons to navigate:

- +
  • Run → Executes the code in the editor
  • Copy → Copies the example code to the editor
  • diff --git a/translations/fr/README.md b/translations/fr/README.md new file mode 100644 index 00000000..697db85e --- /dev/null +++ b/translations/fr/README.md @@ -0,0 +1,21 @@ +## Copyright (C) +Try Ruby version 4 French translation, 2018, _Olivier Lacan_ + +## The MIT License +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/translations/fr/try_ruby_10.md b/translations/fr/try_ruby_10.md new file mode 100644 index 00000000..131aac34 --- /dev/null +++ b/translations/fr/try_ruby_10.md @@ -0,0 +1,26 @@ +--- +lang: FR +title: 30 minutes de libre ? Essaie Ruby ! +answer: +class: stretcher chapmark +ok: +error: +--- + +Ruby est un language de programmation originaire du Japon et qui a +revolutionné le développement logiciel. + +La beauté de Ruby se situe dans sa balance entre simplicité et puissance. + +Tu peux saisir du code Ruby dans l'éditeur et utiliser les boutons suivants pour naviguer : + +- __Run__ → Execute le code dans l'éditeur +- __Copy__ → Copie l'example de code dans l'éditeur +- __Next__ → Vous permet de sauter à la leçon suivante +- __Back__ → Vous permet de revenir à la leçon précédente +- __Clear__ → Remets l'éditeur à zéro + +Utilise le bouton « planête » +ci-dessus pour changer le language de TryRuby. + +### Clique sur __Next__ pour commencer à apprendre. diff --git a/translations/fr/try_ruby_100.md b/translations/fr/try_ruby_100.md new file mode 100644 index 00000000..447be28a --- /dev/null +++ b/translations/fr/try_ruby_100.md @@ -0,0 +1,18 @@ +--- +lang: FR +title: Stop, t'es barge ! +answer: ^\d{1,}$ +ok: Seuls les strings peuvent être inversés +error: +--- + +On ne peut pas inverser le nombre quarante. J'imagine que tu +pourrais tenir ton moniteur en face d'un mirroir, mais inverser un +nombre n'est pas franchement très logique. + +Ruby a lancé un message d'erreur. Ruby t'explique qu'il n'y a pas de +méthode pour inverser des nombres. + +Tu pourrais peut-être transformer ce nombre en string pour commencer : + + 40.to_s.reverse diff --git a/translations/fr/try_ruby_110.md b/translations/fr/try_ruby_110.md new file mode 100644 index 00000000..a967a384 --- /dev/null +++ b/translations/fr/try_ruby_110.md @@ -0,0 +1,24 @@ +--- +lang: FR +title: Les garçons sont différents des filles +answer: \[\] +ok: Bon, d'accord, voilà une liste vide. +error: +--- + +Et les nombres sont différents des strings. + +Bien qu'il soit possible d'utiliser des méthodes sur n'importe quel +objet avec Ruby, certaines méthodes ne fonctionnent qu'avec certains +types de choses. Mais il est toujours possible de passer d'un type à un +autre avec les méthodes "to" to Ruby. + +- __to_s__ convertit les choses en __s__trings +- __to_i__ convertit les choses en __i__ntegers (nombres entiers) +- __to_a__ convertit les choses en __a__rrays + +__Qu'est-ce qu'un array ?!__ + +C'est une liste. Saisis une paire de crochets : + + [] diff --git a/translations/fr/try_ruby_120.md b/translations/fr/try_ruby_120.md new file mode 100644 index 00000000..8dff828d --- /dev/null +++ b/translations/fr/try_ruby_120.md @@ -0,0 +1,21 @@ +--- +lang: FR +title: Faire la queue +answer: ^\[(\d+)(,\s*\d+){3,}\]$ +ok: Excellent +error: Essaye d'ajouter un quatrième nombre à la liste +--- + +Les listes (arrays) stockent des choses __dans un ordre défini__. + +C'est un peu comme faire la queue pour acheter une baguette. Tu es +derrière quelqu'un et ce sera impensable de les pousser pour passer +devant, non? Et le mec derrière toi, tu gardes un œil sur lui, juste au +cas où ? + +Voilà une liste pour toi. Des numéros de lotterie : + + [12, 47, 35] + +Essaie d'ajouter un nombre à cette liste: saisis une virgule après 35 +suivie d'un nombre. L'espace est facultatif. diff --git a/translations/fr/try_ruby_130.md b/translations/fr/try_ruby_130.md new file mode 100644 index 00000000..859e1daa --- /dev/null +++ b/translations/fr/try_ruby_130.md @@ -0,0 +1,13 @@ +--- +lang: FR +title: Un d'entre eux lève la main +answer: ^47$ +ok: D'accord +error: +--- + +Une liste de numéros de lotterie. Lequel est le plus grand ? + +Essaye: + + [12, 47, 35].max diff --git a/translations/fr/try_ruby_140.md b/translations/fr/try_ruby_140.md new file mode 100644 index 00000000..148aab45 --- /dev/null +++ b/translations/fr/try_ruby_140.md @@ -0,0 +1,14 @@ +--- +lang: FR +title: Ranger une liste proprement +answer: ^\[(\d+)(,\s*\d+){2,}\]$ +ok: Sauvegardé ! +error: +--- + +Bien, bien. Cela dit c'est ennuyant d'avoir à retaper cette liste chaque +fois que tu en as besoin, non ? + +Sauvegardons nos numéros dans un ticket comme ça : + + ticket = [12, 47, 35] diff --git a/translations/fr/try_ruby_150.md b/translations/fr/try_ruby_150.md new file mode 100644 index 00000000..2ab986f9 --- /dev/null +++ b/translations/fr/try_ruby_150.md @@ -0,0 +1,12 @@ +--- +lang: FR +title: Maintenant entre ticket +answer: \[(\d+(, )?){2,}\] +load: ticket = [12, 47, 35] +ok: Réstoré! +error: +--- + +Maintenant, saisi: + + ticket diff --git a/translations/fr/try_ruby_160.md b/translations/fr/try_ruby_160.md new file mode 100644 index 00000000..b90af4b4 --- /dev/null +++ b/translations/fr/try_ruby_160.md @@ -0,0 +1,27 @@ +--- +lang: FR +title: Sauvegardé, rangé proprement +answer: \[12, 35, 47\] +load: ticket = [12, 47, 35] +ok: Tu as organisé la liste en ordre +error: +--- + +Tu as gardé tes numéro de lotto en les rangeant dans une __variable__ +nommée ticket. Mais n'importe quel autre nom, comme _lalistedejimmy_, +aurait aussi fait l'affaire. + +Comme tu découvriras, la programmation c'est surtout jongler avec des +variables. + +Mettons les numéros de lotto dans l'ordre. + +Utilise: + + ticket.sort! + +Tu avais une liste. Tu as organisé la liste dans l'ordre. La variable +ticket a maintenant changé Est-ce que tu as remarqué que la méthode +_sort!_ a un gros point d'exclamation à la fin ? Souvent les méthodes +Ruby crient comme ça lorsqu'elle modifient une variable pour de bon. +C'est rien de grave, juste une ponctuation. diff --git a/translations/fr/try_ruby_170.md b/translations/fr/try_ruby_170.md new file mode 100644 index 00000000..38d62934 --- /dev/null +++ b/translations/fr/try_ruby_170.md @@ -0,0 +1,37 @@ +--- +lang: FR +title: Élementaire +answer: ^(12|35|47)$ +load: ticket = [12, 47, 35] +ok: D'accord +error: Presque +--- + +Donc nous avons stocké nos numéros de loterie dans la variable ticket. +Comment faire pour les retrouver ? + +On a déjà vu qu'il est possible d'obtenir le numéro le plus élevé avec __max__. +On peut également obtenir le premier (__first__) ou le dernier (__last__) +élement de la liste. +Mais que faire si on a besoin d'un élement specifique de la liste? + +### [ ] +Ruby utilise des crochets droits [ ] pour viser un élement. +Les crochets droits sont très commun dans Ruby. +Ce sont comme des lunettes de visée pour aligner une cible. Exactement. +Ces crochets signifient, "Je cherche ____". Prêt, vises. + +Recupèrons tous nos numéros de lotto : + + puts ticket[0] + puts ticket[1] + puts ticket[2] + +Pourquoi utiliser [0], [1], [2] ? + +Et pourquoi pas [1], [2] and [3] ? Est-ce que c'est une éspèce de truc Zen japonais ? +Non, nous autre les amis des ordinateurs on préfère juste commencer à compter à +partir de zéro. C'est pas juste un truc dans Ruby, ça s'appelle _l'indexation à +base zéro_ et c'est utilisé dans la plupart des languages de programmation. + +> Un petit rappel : tu peux utiliser le bouton __Copy__ pour recopier l'exemple de code dans l'éditeur. diff --git a/translations/fr/try_ruby_180.md b/translations/fr/try_ruby_180.md new file mode 100644 index 00000000..7818e7da --- /dev/null +++ b/translations/fr/try_ruby_180.md @@ -0,0 +1,34 @@ +--- +lang: FR +title: Le résumé #2 est arrivé +answer: \w+ +class: stretcher chapmark +load: poem = "My toast has flown from my hand\nAnd my toast has gone to the moon.\nBut when I saw it on television,\nPlanting our flag on Halley's comet,\nMore still did I want to eat it.\n" +ok: Est-ce que ça rime? +error: +--- + +Jettons un œil à ce qui s'est passé pendant ta deuxième minute: + +### Erreurs +Si tu essayes d'inverser un nombre ou de faire des choses bizarres, Ruby +te dira ce qui ne va pas. + +### Listes +Les arrays sont des listes pour stocker des choses dans un ordre +spécifique. On sait égaelement comment créer un array et récuperer des +élement dans un array. + +### Variables +Les variables sauvegardent une chose et lui donne un nom. Tu as utilisé +le signe égal pour ça. Par example: ticket = [14, 37, 18]. + +### 2/8 +En tout il y a huit sections. Tu as fini deux-huitièmes du chemin! C'est +pas si compliqué, non? Et il y a plein de bonnes choses à suivre. + +Changeons de direction pour un instant. J'ai mis un petit bout de poésie +pour toi dans une certaine variable. +Jette un œil. Saisi: + + puts poem diff --git a/translations/fr/try_ruby_190.md b/translations/fr/try_ruby_190.md new file mode 100644 index 00000000..346ae874 --- /dev/null +++ b/translations/fr/try_ruby_190.md @@ -0,0 +1,17 @@ +--- +lang: FR +title: Malheuresement, la poésie de biscotte c'est pas ton truc +answer: (toast){0} +load: prev +ok: Excellent +error: Ça sent toujours la biscotte pour moi +--- + +Eh, c'est pas grave. T'es pas obligé d'aimer ça. Laisses toi aller et +améliore mon poème. Au lieu d'une biscotte, tu peux essayer un melon +pourquoi pas. Essaie de voir ce nouveau poème: + + poem.gsub("toast", "honeydew") + +La méthode __gsub__ est un raccourci pour *sub*stitution *g*lobale. +Elle remplace toutes les instances du mot "toast" avec "honeydew". diff --git a/translations/fr/try_ruby_20.md b/translations/fr/try_ruby_20.md new file mode 100644 index 00000000..0020ddf4 --- /dev/null +++ b/translations/fr/try_ruby_20.md @@ -0,0 +1,19 @@ +--- +lang: EN +title: Using the editor +answer: ^\d{1,}$ +ok: Good! You did a bit of math. See how the answer popped out? +error: Type 2 + 6 in the editor +--- + +The editor window at the bottom is where you type your Ruby code, hit the __Run__ button and +watch it run! + +For example, try typing some math. Like: + + 2 + 6 + +The output of your program should show itself at the output window at the top. +There should also be a line that tells you how well you did. + +> Alternatively you can hit the __Copy__ button to copy the example code to the editor. diff --git a/translations/fr/try_ruby_200.md b/translations/fr/try_ruby_200.md new file mode 100644 index 00000000..9033f3d0 --- /dev/null +++ b/translations/fr/try_ruby_200.md @@ -0,0 +1,12 @@ +--- +lang: EN +title: Ready, Aim +answer: ^\n.ti tae ot (.+) +load: prev +ok: Okay, sure. So the whole poem has been turned backwards. +error: +--- + +Here's a question: what happens when we reverse this whole poem? + + poem.reverse diff --git a/translations/fr/try_ruby_210.md b/translations/fr/try_ruby_210.md new file mode 100644 index 00000000..c819ace1 --- /dev/null +++ b/translations/fr/try_ruby_210.md @@ -0,0 +1,17 @@ +--- +lang: EN +title: Too Much Reversal +answer: ^\["More still did (.+) +load: prev +ok: Yes, almost what we want +error: +--- + +So the whole poem's been turned backwards, letter-by-letter. I really wanted to just reverse the lines though. +Move the last line up to first and the first line down to last. + +Backwards, but not __that__ backwards. + +Here's how: + + poem.lines.reverse diff --git a/translations/fr/try_ruby_220.md b/translations/fr/try_ruby_220.md new file mode 100644 index 00000000..e831019c --- /dev/null +++ b/translations/fr/try_ruby_220.md @@ -0,0 +1,21 @@ +--- +lang: EN +title: Ringlets of Chained Methods +answer: ^More still did (.+) +load: prev +ok: Good show, my friend! The join method took that array of lines and put them together into a string. +error: +--- + +So what do you see? What happened there? You typed __poem.lines.reverse__ and what happened? + +Two things happened. You turned the poem into a list using lines. +Lines decides the way the string is split up and converts it into an Array. + +Then, you reversed that list. You had each line. You reversed them. That's it. + +Let's tack one more method on the end there: + + puts poem.lines.reverse.join + +Combining methods like this is called _method chaining_. \ No newline at end of file diff --git a/translations/fr/try_ruby_230.md b/translations/fr/try_ruby_230.md new file mode 100644 index 00000000..750633ab --- /dev/null +++ b/translations/fr/try_ruby_230.md @@ -0,0 +1,30 @@ +--- +lang: EN +title: Of All the Summaries, #3 is Here Now +answer: \{\} +class: stretcher chapmark +load: prev +ok: You've made an empty hash ! +error: +--- + +### Exclamations +Methods may have exclamations (and also question marks) in their name. +These are just there to better explain what their function is. No big deal. + +### String manipulation +Search and change strings + +### Chaining +Chaining methods lets you get a lot more done. Break up a poem, reverse it, reassemble it: +__poem.lines.reverse.join__ + +At this point, you may want to tinker with the poem a bit more. A complete list of all the String +methods is here. + +Go ahead and try a few, such as: poem.downcase or poem.swapcase + +## Ready ? +When you feel ready to move on, type: + + books = {} diff --git a/translations/fr/try_ruby_240.md b/translations/fr/try_ruby_240.md new file mode 100644 index 00000000..3bb1fc32 --- /dev/null +++ b/translations/fr/try_ruby_240.md @@ -0,0 +1,27 @@ +--- +lang: EN +title: A Wee Blank Book +answer: ^(splendid|quite_good|mediocre|quite_not_good|abyssmal)$ +load: books = {} +ok: Yes that's a new review +error: Use one of splendid, quite_good, mediocre, quite_not_good, abyssmal. Don't forget the colon +--- + +You've made an empty __hash__. A hash is like an array, only every one of its elements has a name. + +We're going to stuff some miniature book reviews in our new hash. Here's our rating system: + +- :splendid → a masterpiece +- :quite\_good → enjoyed, sure, yes +- :mediocre → equal parts great and terrible +- :quite\_not\_good → notably bad +- :abyssmal → steaming wreck + +To rate a book, put the title in square brackets and put the rating after the equals. For example: + + books["Gravitys Rainbow"] = :splendid + +> By now I think it is only fair to tell you that all lessons in TryRuby are separate from each other. +> So if you go crazy typing book reviews here, you can only use 'em in this lesson. +> If you want to use your reviews in the next lesson you should copy/paste them. +> Don't worry about this too much, each lesson has plenty of predefined stuff for you to play around with. diff --git a/translations/fr/try_ruby_250.md b/translations/fr/try_ruby_250.md new file mode 100644 index 00000000..3b5c6b05 --- /dev/null +++ b/translations/fr/try_ruby_250.md @@ -0,0 +1,28 @@ +--- +lang: EN +title: More Bite-Size Reviews +answer: [3-9] +load: books = {"Gravitys Rainbow" => :splendid} +ok: See, the length method works on strings, array's and hashes. +error: +--- + +Keep going, fill it up with reviews. And, if you want to see the whole list, just type: __puts books__ + +Again, the ratings are: :splendid, :quite\_good, :mediocre, :quite\_not\_good and :abyssmal. + +These ratings are not strings. When you place a colon in front of a simple word, you get a __symbol__. +Symbols are cheaper than strings (in terms of computer memory.) If you use a word over and over in your program, +use a symbol. Rather than having thousands of copies of that word in memory, the computer will store the symbol only +__once__. + +More importantly, a symbol tells you that is not just any old word but has a meaning within your program. + +Enter 2 more bookreviews, use __books.length__ to see how many reviews there are in the hash: + + books["The deep end"] = :abyssmal + books["Living colors"] = :mediocre + + puts books + + puts books.length diff --git a/translations/fr/try_ruby_260.md b/translations/fr/try_ruby_260.md new file mode 100644 index 00000000..5bb17c7e --- /dev/null +++ b/translations/fr/try_ruby_260.md @@ -0,0 +1,20 @@ +--- +lang: EN +title: Wait, Did I Like Gravity's Rainbow? +answer: ^(splendid|quite_good|mediocre|quite_not_good|abyssmal)$ +load: books = {"Gravitys Rainbow" => :splendid, "The deep end" => :abyssmal, "Living colors" => :mediocre} +ok: I liked it a lot +error: +--- + +One great thing about Ruby is that names are often reused, which means fewer names you need to remember. + +Remember how we retrieved items from an array using a number: +__puts ticket[1]__. + +For a hash this works the same way, except we don't use a number to get an element but a name. + +So, if you'd like to look up one of your old reviews, again put the title in the square. But leave off the equals. +Just like this: + + puts books["Gravitys Rainbow"] diff --git a/translations/fr/try_ruby_270.md b/translations/fr/try_ruby_270.md new file mode 100644 index 00000000..11f43c99 --- /dev/null +++ b/translations/fr/try_ruby_270.md @@ -0,0 +1,19 @@ +--- +lang: EN +title: Hashes as Pairs +answer: ^\[".*"\] +load: prev +ok: You found the keys +error: +--- + +Keep in mind that hashes won't keep things in order. That's not their job. It'll just pair up +two things: a __key__ and a __value__. + +In your reviews, the book's title is the key and the rating is the value. + +If you want to just see the titles of all the books you've reviewed: + + books.keys + +You can also try this with .values instead of .keys. \ No newline at end of file diff --git a/translations/fr/try_ruby_280.md b/translations/fr/try_ruby_280.md new file mode 100644 index 00000000..edee0dba --- /dev/null +++ b/translations/fr/try_ruby_280.md @@ -0,0 +1,27 @@ +--- +lang: EN +title: Are You Harsh? +answer: "mediocre" +load: books = {"Gravitys Rainbow" => :splendid, "The deep end" => :abyssmal, "Living colors" => :mediocre, "Bumblebees" => :mediocre} +ok: Great, wow! You've made a scorecard of your ratings +error: +--- + +So are you giving out harsh, unfair reviews? Let's keep score with a new hash __ratings__: + +Then, okay, now let's count up your reviews. Just stay with me. Type: + + ratings = Hash.new {0} + + books.values.each { |rate| + ratings[rate] += 1 + } + + puts ratings + +The straight line in the code is the pipe character, probably located right above the Enter key +on your keyboard. + +That _+= 1_ line means: increase the value by 1. + +Don't worry if you don't understand everything that is going on here. It will be revealed later. diff --git a/translations/fr/try_ruby_290.md b/translations/fr/try_ruby_290.md new file mode 100644 index 00000000..e41cd742 --- /dev/null +++ b/translations/fr/try_ruby_290.md @@ -0,0 +1,18 @@ +--- +lang: EN +title: A Tally +answer: \w+ +ok: Yodelay! +error: +--- + +One of the amazing new things we've just used is a __block__. We're going to explore these more +in this and the next lesson. But, basically, a block is a bit of Ruby code surrounded by curly +braces. + +Let's try another block: + + 5.times { print "Odelay! " } + +Blocks are always attached to methods. Like the __times__ method, which takes the block and runs +the code over and over. (In our example: five times.) \ No newline at end of file diff --git a/translations/fr/try_ruby_30.md b/translations/fr/try_ruby_30.md new file mode 100644 index 00000000..a504f1c7 --- /dev/null +++ b/translations/fr/try_ruby_30.md @@ -0,0 +1,13 @@ +--- +lang: EN +title: Numbers and Math +answer: ^[0-9\.,-]{1,}$ +ok: Good +error: +--- + +Ruby recognizes numbers and mathematic symbols. You could try some other math like: + + 4 * 10 + 5 - 12 + 30 / 4 \ No newline at end of file diff --git a/translations/fr/try_ruby_300.md b/translations/fr/try_ruby_300.md new file mode 100644 index 00000000..59198554 --- /dev/null +++ b/translations/fr/try_ruby_300.md @@ -0,0 +1,23 @@ +--- +lang: EN +title: Have you got the time? +answer: ^[0-9]$ +ok: You timed it just right! +error: Run the block 0 to 9 times +--- + +As we saw in the first example with a block (when counting ratings) we can pass a value to the block. Which +values are __passed__ is determined by the method that is running the block. + +The values that are __received__ by the block are placed in the variable name at the beginning of the block, +between two pipe symbols: | + +Let's try that with this block: + + 5.times { |time| + puts time + } + +Here, method __.times__ sends a value to variable __|time|__. But note that variable time is only known within the block. + +> Did you notice that you can split code over multiple lines. This makes it a bit easier to read. diff --git a/translations/fr/try_ruby_310.md b/translations/fr/try_ruby_310.md new file mode 100644 index 00000000..b3bcd239 --- /dev/null +++ b/translations/fr/try_ruby_310.md @@ -0,0 +1,24 @@ +--- +lang: EN +title: Now Arriving at Summary #4 +answer: +class: stretcher chapmark +ok: +error: +--- + +This last lesson was a bit longer. You've probably used up three minutes learning about: + +### Hashes +The little dictionary with the curly pages: __{}__ + +### Symbols +Tiny, efficient code words with a colon, like: __:splendid__ + +### Blocks +Chunks of code which can be tacked on to many of Ruby's methods. Here's the code you used to +build a scorecard: +__books.values.each { |rate| ratings[rate] += 1 }__ + +### Next +In the next lesson we will delve al little bit deeper into methods. diff --git a/translations/fr/try_ruby_320.md b/translations/fr/try_ruby_320.md new file mode 100644 index 00000000..7e67a5e7 --- /dev/null +++ b/translations/fr/try_ruby_320.md @@ -0,0 +1,38 @@ +--- +lang: EN +title: To (be) or not to (be) +answer: +load: poem = "My toast has flown from my hand\nAnd my toast has gone to the moon.\nYada yada yada\n" +ok: +error: +--- + +One other little thing we haven't really talked about openly: method arguments. +Remember when we changed the poem a little bit ? We used: +__poem.gsub("toast", "honeydew")__ + +The gsub method needs 2 arguments, which we passed to gsub by including two strings between +parenthesis. _Arguments tell the method exactly what to do._ + +### Parenthesis +Actually, most of the time Ruby doesn't mind if you omit the parenthesis. So this would have +worked too: +__poem.gsub "toast", "honeydew"__ + +We have already used another method with a parameter. Many times in fact, though it was not very +obvious: + + puts "Hello" + puts("Hello") + +Yes __puts__ is also a method. Using puts with or without parenthesis is the same to Ruby, but the +version without parenthesis is a bit easier to read. And it saves you valuable typing time ! + +> So I guess the conclusion is that you can do whatever you like with parenthesis as long as your +> code reads nicely. + +### to (be) or not to (be) +So if _to_ is a method and _be_ is an argument we now know the answer to this age old question. +It is really just a matter of preference whether you want _to be_ or _to(be)_. + +Are you in the mood for more Shakespeare ? Read on. diff --git a/translations/fr/try_ruby_330.md b/translations/fr/try_ruby_330.md new file mode 100644 index 00000000..1b1638ab --- /dev/null +++ b/translations/fr/try_ruby_330.md @@ -0,0 +1,33 @@ +--- +lang: EN +title: The Taming of the Shrew +answer: ^tame +ok: Good good ! +error: +--- + +You totally know how to use Ruby now. I mean you've got down the essentials. +You just need to keep learning more methods and try out more complex blocks. + +But there's one side of Ruby we haven't settled. Making your own methods. +__Ahem!__ Let's get it over with then. + +Next to using Ruby's built in methods (like puts, sort, times) you can define +your own methods. Why is that a good idea? Two reasons: + +### To make your program shorter +If you have to do the same thing in more than one part of your code it is easier +to put that code in a separate method. Your code will be shorter. + +### To make your code easier to read +Suppose your program needs to do a lot of different things. +You __could__ stuff all code into one long piece. But it would be very difficult to +read and understand that code later. + +Instead you should cut up your code in different methods and give each method an easy to +understand English name. You will thank yourself later. + +So how do we define a method ? Like this: + + def tame( number_of_shrews ) + end diff --git a/translations/fr/try_ruby_340.md b/translations/fr/try_ruby_340.md new file mode 100644 index 00000000..0da857a1 --- /dev/null +++ b/translations/fr/try_ruby_340.md @@ -0,0 +1,24 @@ +--- +lang: EN +title: In Ruby, Def Leppard means: define method Leppard +answer: ^tame +ok: Tame is not lame +error: +--- + +Hey, okay, you done it. You're making your own method. You started with def, followed by the name of the method. +And a list of arguments which the method will need. This isn't too scary and dangerous! +All we have to do is fill it up with Ruby and finish it up with end. + +Here's the code: + + def tame( number_of_shrews ) + number_of_shrews.times { + puts "Tamed a shrew" + } + end + +> __P.S.__ +> If you don't get the title of this chapter. +> Def Leppard +> is the name of a, once famous, English rock band. diff --git a/translations/fr/try_ruby_350.md b/translations/fr/try_ruby_350.md new file mode 100644 index 00000000..8d88d089 --- /dev/null +++ b/translations/fr/try_ruby_350.md @@ -0,0 +1,12 @@ +--- +lang: EN +title: The Ripened Fruit of Your Own Creation +answer: ^Tamed a shrew +ok: That'll show those shrews +error: +load: def tame(number_of_shrews);number_of_shrews.times{puts "Tamed a shrew"};end; +--- + +A new method is born. Let us use it now: + + tame 5 diff --git a/translations/fr/try_ruby_360.md b/translations/fr/try_ruby_360.md new file mode 100644 index 00000000..a2b3d9d5 --- /dev/null +++ b/translations/fr/try_ruby_360.md @@ -0,0 +1,29 @@ +--- +lang: EN +title: Give and take +answer: \d+ +ok: Right on. Bravo. +error: +--- + +Most methods do not only want some parameters as input, but will also __give something back__. +I have changed our method a bit so it will return a value to you. Try it: + + def tame( number_of_shrews ) + number_of_shrews.times { + puts "Tamed a shrew" + } + return number_of_shrews + end + + puts tame(3) + +### Return +And, since you're getting so advanced and capable here, one other tip: +you can omit the word __return__ from the last line of the method. +Ruby will automagically return the last value that was used inside the method. + +So we can change the last line to just: __number\_of\_shrews__. + +But since method __.times__ also returns the _number\_of\_shrews_ we can +remove the entire last line. So in fact our original method already did what we wanted all along ! diff --git a/translations/fr/try_ruby_370.md b/translations/fr/try_ruby_370.md new file mode 100644 index 00000000..8098d3d5 --- /dev/null +++ b/translations/fr/try_ruby_370.md @@ -0,0 +1,27 @@ +--- +lang: EN +title: Hello, Who's There? And Summary #5 Waves Its Hat! +answer: +class: stretcher chapmark +ok: +error: +--- + +Well done, well done, well done, well done! + +Truly, truly, truly, truly, truuuuuuuuly! + +Here's the last few minutes of your life in review: + +### Methods +Methods can be defined with __def__ and have a name. Methods make your program shorter +and easier to read. + +### Parameters +Methods can have parameters. + +### Return values +Methods (almost) always return a value. + +## Now +To (be) or not to (be) is not a question to you anymore. Are you ready for some more Shakespeare ? diff --git a/translations/fr/try_ruby_380.md b/translations/fr/try_ruby_380.md new file mode 100644 index 00000000..88909568 --- /dev/null +++ b/translations/fr/try_ruby_380.md @@ -0,0 +1,33 @@ +--- +lang: EN +title: The world is our oyster +answer: ^\{\"William +ok: Good. Bit difficult to read. +error: +load: def get_shakey;JSON.parse("{\"William Shakespeare\": {\"1\": {\"title\": \"The Two Gentlemen of Verona\", \"finished\": 1591},\"2\": {\"title\": \"The Taming of the Shrew\", \"finished\": 1591},\"3\": {\"title\": \"Henry VI, Part 2\", \"finished\": 1591},\"4\": {\"title\": \"Henry VI, Part 3\", \"finished\": 1591},\"5\": {\"title\": \"Henry VI, Part 1\", \"finished\": 1592},\"6\": {\"title\": \"Titus Andronicus\", \"finished\": 1592},\"7\": {\"title\": \"Richard III\", \"finished\": 1593},\"8\": {\"title\": \"Edward III\", \"finished\": 1593},\"9\": {\"title\": \"The Comedy of Errors\", \"finished\": 1594},\"10\": {\"title\": \"Love's Labour's Lost\", \"finished\": 1595},\"11\": {\"title\": \"Love's Labour's Won\", \"finished\": 1596},\"12\": {\"title\": \"Richard II\", \"finished\": 1595},\"13\": {\"title\": \"Romeo and Juliet\", \"finished\": 1595},\"14\": {\"title\": \"A Midsummer Night's Dream\", \"finished\": 1595},\"15\": {\"title\": \"King John\", \"finished\": 1596},\"16\": {\"title\": \"The Merchant of Venice\", \"finished\": 1597},\"17\": {\"title\": \"Henry IV, Part 1\", \"finished\": 1597},\"18\": {\"title\": \"The Merry Wives of Windsor\", \"finished\": 1597},\"19\": {\"title\": \"Henry IV, Part 2\", \"finished\": 1598},\"20\": {\"title\": \"Much Ado About Nothing\", \"finished\": 1599},\"21\": {\"title\": \"Henry V\", \"finished\": 1599},\"22\": {\"title\": \"Julius Caesar\", \"finished\": 1599},\"23\": {\"title\": \"As You Like It\", \"finished\": 1600},\"24\": {\"title\": \"Hamlet\", \"finished\": 1601},\"25\": {\"title\": \"Twelfth Night\", \"finished\": 1601},\"26\": {\"title\": \"Troilus and Cressida\", \"finished\": 1602},\"27\": {\"title\": \"Sir Thomas More\", \"finished\": 1604},\"28\": {\"title\": \"Measure for Measure\", \"finished\": 1604},\"29\": {\"title\": \"Othello\", \"finished\": 1604},\"30\": {\"title\": \"All's Well That Ends Well\", \"finished\": 1605},\"31\": {\"title\": \"King Lear\", \"finished\": 1606},\"32\": {\"title\": \"Timon of Athens\", \"finished\": 1606},\"33\": {\"title\": \"Macbeth\", \"finished\": 1606},\"34\": {\"title\": \"Antony and Cleopatra\", \"finished\": 1606},\"35\": {\"title\": \"Pericles, Prince of Tyre\", \"finished\": 1608},\"36\": {\"title\": \"Coriolanus\", \"finished\": 1608},\"37\": {\"title\": \"The Winter's Tale\", \"finished\": 1611},\"38\": {\"title\": \"Cymbeline\", \"finished\": 1610},\"39\": {\"title\": \"The Tempest\", \"finished\": 1611},\"40\": {\"title\": \"Cardenio\", \"finished\": 1613},\"41\": {\"title\": \"Henry VIII\", \"finished\": 1613},\"42\": {\"title\": \"The Two Noble Kinsmen\", \"finished\": 1614}}}");end; +--- + +So far we have been running programs that only use things that we have typed ourselves. +Which is nice, I mean that _Odelaying_ was epic, but this the internet era so it is about +time we included the rest of the world in our programming efforts. + +Many, many, many websites are available that you can ask for information. For instance +this link will give you all current Google news feeds +about Ruby. + +Your web browser will probably display it quite nicely for you. If you look at the source +(type: control-U) you will see a long string of strangely formatted text. In the Google example +it is in the __rss__ format. + +### Formats +There are many other formats, with strange names, available and used on the web, like: +html, xml and json. Yes, even this very website uses a couple of these. + +I have prepared a method for you that will fetch a list of the complete works of William +Shakespeare from the internet. +(Don't worry it actually comes from the same server that this website runs on, so +we're not bothering anyone.) + +Get the data with: + + get_shakey diff --git a/translations/fr/try_ruby_390.md b/translations/fr/try_ruby_390.md new file mode 100644 index 00000000..f6872930 --- /dev/null +++ b/translations/fr/try_ruby_390.md @@ -0,0 +1,53 @@ +--- +lang: EN +title: Noble Kinsmen +answer: ^The Two Noble Kinsmen$ +ok: That's much better +error: +load: prev +--- + +Okay we now have a list of plays from the internet. The list was in the json format. +Fortunately for us Ruby kindly provides a method to convert json data to a Ruby hash. +The _get\_shakey_ method already did that for us. + +But since the structure of the json data is retained in the hash, it is still a bit difficult to read. +Let us write a method to display the plays nicely. + +If you inspect the list of plays carefully you will see that it has a kind of nested +structure. (This is actually quite common in data you get from the internet.) +Looks like this: + +
      +
    • "William Shakespeare" +
        +
      • "1" +
          +
        • "title": "The Two Gentlemen of Verona"
        • +
        • "finished": 1591
        • +
        +
      • +
      • "2" +
          +
        • "title": "The Taming of the Shrew"
        • +
        • "finished": 1591
        • +
        +
      • +
      • ...
      • +
      +
    • +
    + +To list the plays we first have to access the top "William Shakespeare" hash element by it's name. +Next we have to __iterate__ through each element below it. + +Ruby has a method for iterating. It is called __each__. We have seen it before when +creating our book rating system. + +Everything that method __each__ returns is passed to a block: + + s = get_shakey + + s["William Shakespeare"].each { |key, val| + puts val["title"] + } diff --git a/translations/fr/try_ruby_40.md b/translations/fr/try_ruby_40.md new file mode 100644 index 00000000..106ca039 --- /dev/null +++ b/translations/fr/try_ruby_40.md @@ -0,0 +1,27 @@ +--- +lang: EN +title: Putting it differently +answer: ^[0-9\.,-]{1,}$ +ok: Well put +error: +--- + +Did you notice that if you typed more than one formula you only saw the answer for the last one. +What is going on ? + +> To make this website easier to use I have told Ruby to copy the result of your program to the +> output screen at the top. So when you type a formula you get to see the results. +> __But only the last result.__ And only if the output is still empty. + +So when you entered 2 or more formula's, Ruby only showed the result of the last formula. + +Of course you have the power to control the screen ! Just type __puts__ before each formula +(with a space in between). Puts means: *'put something on the screen'*. + +Try this: + + puts 4 * 10 + puts 5 - 12 + puts 30 / 4 + +Now remove the puts from the last formula and see what happens. diff --git a/translations/fr/try_ruby_400.md b/translations/fr/try_ruby_400.md new file mode 100644 index 00000000..b9bd7cda --- /dev/null +++ b/translations/fr/try_ruby_400.md @@ -0,0 +1,41 @@ +--- +lang: EN +title: All together now +answer: ^4$ +ok: Yes, Shakespeare wrote 4 plays in 1591 +error: Answer for the year 1591 should be 4 +load: prev +--- + +Now suppose we only want to know the names and number of plays written by Shakespeare +in a certain year. + +Ruby lets us __select__ values from a hash. The select method uses a block to let us +define what to select and returns what it found. + +We can then use the results returned by __select__ in the __each__ method as before by +simply adding it after the select block. This is another example of method chaining, which we saw +earlier when reversing a poem. + +I have prepared the __count\_plays__ method for you. See if you can find out how many plays +were written by Shakespeare in the year __1591__. Try this: + + def count_plays(year) + s = get_shakey + + s["William Shakespeare"] + .select { |k, v| + v["finished"] == year + }.each { |key, val| + puts val["title"] + }.count + end + + puts count_plays(0) + +Did you notice that I chained the count method at the end of the each method. This gives +us a return value for the __count\_plays__ method. + +There is another possibility for chaining here. See that loney line __s = get_shakey__. +You could add the __["William Shakespeare"].select { |k, v|__ at the end of get_shakey +(no dot needed in this case). diff --git a/translations/fr/try_ruby_410.md b/translations/fr/try_ruby_410.md new file mode 100644 index 00000000..1ec0b868 --- /dev/null +++ b/translations/fr/try_ruby_410.md @@ -0,0 +1,40 @@ +--- +lang: EN +title: All's Well That Ends Well +answer: All's Well That Ends Well +ok: True +error: Use 1605 as the second parameter +load: prev +--- + +Okay, we got some data from the internet, we selected what we wanted and printed it out. +What is left to improve? We could print the results a bit prettier. Like add the year +and align titles and years. + +This means printing several values on one line. Ruby has a neat way of doing +that. It is just like printing a string like: __puts "Hi, my name is Jimmy"__. +But instead of the literal value _Jimmy_ we use the value of a variable. + +First replace __Jimmy__ with __#{}__. If Ruby sees a hash symbol # followed by a curly brace { +it looks for a variable between the first brace and the following closing brace }. +So we can use this: __"Hi, my name is \#{name}"__. + +Let's change our code a bit + + def print_plays(year_from, year_to) + get_shakey["William Shakespeare"] + .select { |k, v| + year_from <= v["finished"] && + year_to >= v["finished"] + }.each { |k, v| + puts "#{v["title"].ljust(30)} #{v["finished"]}" + } + end + print_plays(1600, 1605) + +I have added __.ljust(30)__ to the title. This way the title is _left justified_ with a minimum +length of 30 characters so the years align nicely. + +See if you can change the ouput of the program so that it shows the plays like this: __1600 -> As You Like It__ + +__All's Well That Ends Well ?__ Hey we're not done yet, but the end is in sight ! diff --git a/translations/fr/try_ruby_420.md b/translations/fr/try_ruby_420.md new file mode 100644 index 00000000..ccda7ab9 --- /dev/null +++ b/translations/fr/try_ruby_420.md @@ -0,0 +1,36 @@ +--- +lang: EN +title: If only I new how to make a decision +answer: +ok: +error: +--- + +Decision making, in real life this can be a real problem. Not for us though. +Ruby makes it very easy to make decisions. + + if 1 < 2 + puts "It is true: 1 is less than 2" + end + +The key word here is __if__. If can be placed before a method or after a method, like so: + + puts "It is true: 1 is less than 2" if 1 < 2 + +__If__ is a method that requires one parameter. That parameter can be any expression that you +want to test. The outcome of the expression must be either __true__ or __false__. +Here are a couple of expressions with their outcomes: + + 5 <= 10 # => true + 'abc' == 'def' # => false + true # => true + 123456 # => true + 0 # => true + nil # => false + 'xyz'.empty? # => false + 'a' > 5 # => error: + # comparison of String with + # Numeric failed + +The _if expression_ can take many forms. It can compare literal values (1 < 2), +variables (a < 1) and the return value of a method ('xyz'.empty?). diff --git a/translations/fr/try_ruby_430.md b/translations/fr/try_ruby_430.md new file mode 100644 index 00000000..7de3263c --- /dev/null +++ b/translations/fr/try_ruby_430.md @@ -0,0 +1,34 @@ +--- +lang: EN +title: And Now For the Startling Conclusion +answer: is not equal to 100$ +ok: That's better +error: This can't be right +--- + +Did you see the 2 equal signs in __'abc' == 'def'__? + +This __==__ means __is equal to__. +The single equal sign that we have seen before means __assign a value to a variable__. + +To make it more confusing: you can use the assignment after an if method like this: + + a = 0 + + if a = 100 + puts "Expression is true, but a is now: #{a}" + else + puts "#{a} is not equal to 100" + end + +Change the = into == and see what happens. + +I can guarantee you that you will forget typing the second equal sign regularly. I also +still forget it sometimes. + +### else +In the code above I have added an else expression. This part will be executed when the +__if test-expression__ evaluates to false. + +> There are more variations to this if-then-else theme. You can read more +> here. diff --git a/translations/fr/try_ruby_440.md b/translations/fr/try_ruby_440.md new file mode 100644 index 00000000..7c3c7d0e --- /dev/null +++ b/translations/fr/try_ruby_440.md @@ -0,0 +1,31 @@ +--- +lang: EN +title: Me hungry +answer: ^Me not hungry.$ +ok: Yes +error: No way am I hungry at 10 AM ! +--- + +Okay, this is coming along wonderfully. This is simple stuff for you, but keep in mind that you +didn't know __any Ruby whatsoever__ just fifteen minutes ago! + +Last step. Let's tie it all together, you know? Let's make it chime together like a very nice set +of glistening chimes on the beach in the maginificent sunlight! + +We'll define two methods first and then take a decision: + + def hungry?(time_of_day_in_hours) + puts "Me hungry." + true + end + + def eat_an(what) + puts "Me eat #{what}.\n" + end + + eat_an 'apple' if hungry?(14) + + eat_an 'apple' if hungry?(10) + +Now see if you can change the method __hungry?__ to display __"Me not hungry"__ and returning false +when the time is less than 12. diff --git a/translations/fr/try_ruby_450.md b/translations/fr/try_ruby_450.md new file mode 100644 index 00000000..0b263950 --- /dev/null +++ b/translations/fr/try_ruby_450.md @@ -0,0 +1,33 @@ +--- +lang: EN +title: Summary #6 Which Means You've Come So Far +answer: \{\} +class: stretcher chapmark +ok: Ok, that's an empty hash +error: +--- + +You're a level six Ruby cleric. I mean what a great job you've done. Let's review: + + +### Data +You loaded some data of the internet, traversed a data structure and selected values. + +### Iterating +You iterated all elements of a hash and you chained some more methods. + +### Pretty printing +And if that wasn't enough, you formatted and printed some values in a way that is easy +to read for humans. In fact __you made a real program !__ + +### IF +You learned to take control of your programs with __if__ and __else__ statements. + +## So +What could possibly be next? What could you possibly have to learn now? +Ha, this is the best part. You've come such a long way that we're going +to uncover classes. For two more short lessons and you're done. + +Earlier, we created a hash like this: + + Hash.new diff --git a/translations/fr/try_ruby_460.md b/translations/fr/try_ruby_460.md new file mode 100644 index 00000000..fcb68e5b --- /dev/null +++ b/translations/fr/try_ruby_460.md @@ -0,0 +1,33 @@ +--- +lang: EN +title: Not a School Class, a Working Class +answer: +ok: +error: +--- + +You see, the empty curly braces {} is a shortcut for Hash.new. The new method is used to make objects +of a certain class. Think "class" as in "working class" — a specific group of objects which +are similar, have the same jobs, the same shirts. +What use is a class ? + +### BlurbalizerTM +You just had a brilliant idea for a new app. It is going to be __the__ next instant +messaging platform. You want an app where people can send each other short messages. You call +these messages BlurbsTM. A BlurbTM has a maximum length of just 40 characters. Let's do a mood setting too. + + + +### Where to start +Well, you might store your BlurbsTM entries in a json file, right? +But how would you keep track of the content of the entry and the time it was posted? +And when you loaded the file, how would it look in Ruby? +Would it be a Hash? Or an Array? Or an Array of Arrays? Or something else? + +### Class +I really think you'll want to use a class. You are already familiar with many classes: +Hash, Array, String. +Let's make a new class (returns no output): + + class Blurb + end diff --git a/translations/fr/try_ruby_470.md b/translations/fr/try_ruby_470.md new file mode 100644 index 00000000..12cdde83 --- /dev/null +++ b/translations/fr/try_ruby_470.md @@ -0,0 +1,20 @@ +--- +lang: EN +title: The Stuff Apps are Made of +answer: +ok: +error: +--- + +You've opened up a new BlurbTM class. What is your blog entry made of? +The content, sure. Also, a time when the BlurbTM was posted. And a mood. + +Okay, so you've got the first line of the class, here's the rest: + + class Blurb + attr_accessor :content, :time, :mood + end + +Class names always begin with a capital letter. + +(Still no output) diff --git a/translations/fr/try_ruby_480.md b/translations/fr/try_ruby_480.md new file mode 100644 index 00000000..049990cc --- /dev/null +++ b/translations/fr/try_ruby_480.md @@ -0,0 +1,25 @@ +--- +lang: EN +title: Accessors Are the Dangling Limbs +answer: Blurb: +ok: My first Blurb +error: +load: class Blurb;attr_accessor :content,:time,:mood;end +--- + +Hey, good class, man. You've got a new BlurbTM class. + +In the class definition, you used a method called attr\_accessor. +There are many __attr__ibute methods like this which add little settings to classes. +These attributes are just variables attached to a class. + +Think of it this way. A class is like a person. That star-shaped human thing out there. +And the attributes are the dangling limbs, the different parts that make up a body and +other people can shake hands with. + +### Now +To create a BlurbTM and set the content: + + blurb1 = Blurb.new + puts blurb1 + blurb1.content = "Today Mount Hood Was Stolen!" diff --git a/translations/fr/try_ruby_490.md b/translations/fr/try_ruby_490.md new file mode 100644 index 00000000..95e72478 --- /dev/null +++ b/translations/fr/try_ruby_490.md @@ -0,0 +1,15 @@ +--- +lang: EN +title: An Object, That Neat Little Package +answer: Blurb: +ok: Blurb updated +error: +load: prev;blurb1=Blurb.new;blurb1.content="Today Mount Hood Was Stolen!" +--- + +Go ahead and set the BlurbTM time and mood: + + blurb1.time = Time.now + blurb1.mood = :sick + + puts blurb1 diff --git a/translations/fr/try_ruby_50.md b/translations/fr/try_ruby_50.md new file mode 100644 index 00000000..89c1485b --- /dev/null +++ b/translations/fr/try_ruby_50.md @@ -0,0 +1,13 @@ +--- +lang: EN +title: Say Your Name +answer: [a-zA-Z]{1,1} +ok: Perfect, you've formed a string from the letters of your name +error: +--- + +Sure, computers are handy and fast for math. Let's move on. Want to see your name reversed? + +First type your first name in quotes like this: + + "Jimmy" diff --git a/translations/fr/try_ruby_500.md b/translations/fr/try_ruby_500.md new file mode 100644 index 00000000..a18e0207 --- /dev/null +++ b/translations/fr/try_ruby_500.md @@ -0,0 +1,31 @@ +--- +lang: EN +title: Quickening it Up +answer: ^\d{4} +ok: Noted +error: +--- + +Cool, you're app is awesome. Hey, let's make things a bit easier on you. +You're not going to want to set the time like that every time you BlurbTM. + +You just want to type the content and set the mood, right? + +Let's add an __initialize__ method to our class. This method is called whenever a new BlurbTM +is created. +At the same time we can limit the length of the BlurbTM content to 40 characters. + + class Blurb + attr_accessor :content, :time, :mood + + def initialize(mood, content="") + @time = Time.now + @content = content[0..39] + @mood = mood + end + end + + Blurb.new.time + +(That parameter __content=""__ is there to make sure that we know content is a string, +even if no content parameter is passed to the initialize method.) diff --git a/translations/fr/try_ruby_510.md b/translations/fr/try_ruby_510.md new file mode 100644 index 00000000..a1890dcb --- /dev/null +++ b/translations/fr/try_ruby_510.md @@ -0,0 +1,28 @@ +--- +lang: EN +title: You've Taught Your App to Reject Worthless Things +answer: Blurb: +ok: Blurb added +error: +load: class Blurb;attr_accessor :content,:time,:mood;def initialize(mood, content="");@time=Time.now;@content=content[0..39];@mood=mood;end;end;blurb1=Blurb.new(:sick,"Today Mount Hood Was Stolen!") +--- + +Did you see how inside the class we used the at-symbols (@time). + +__Outside__ the class, we use accessors: + +> __blurb.time = Time.now__ + +but __inside__ we use the __object's variables__: + +> __@time = Time.now__ + +They're the exact same thing, but expressed in two different places of your program. + +### Create another BlurbTM +When a new BlurbTM is created, the initialize method is used to check for any +arguments to new. + +Uh, we need two arguments: + + Blurb2 = Blurb.new :confused, "I can not believe Mt. Hood was stolen!" diff --git a/translations/fr/try_ruby_520.md b/translations/fr/try_ruby_520.md new file mode 100644 index 00000000..d0fc133b --- /dev/null +++ b/translations/fr/try_ruby_520.md @@ -0,0 +1,27 @@ +--- +lang: EN +title: A Giraffe Has Not Stolen Summary #7 +answer: +class: stretcher chapmark +ok: +error: +load: prev;blurb2=Blurb.new :confused, "I can not believe Mt. Hood was stolen!" +--- + +Aha, you're here. And all in one piece. We're still going to make your app real, +but until then, let's review, okay? + +### Classes +Everything in Ruby is some kind of object. Classes explain objects, how a certain object works. +For example, you made a few BlurbTM objects and these objects are explained in the Blurb +class. +In other words: you call them Blurb objects. +You can use classes to (kinda) model real life objects. + +### Accessors +Accessors are variables attached to an object which can be used __outside__ the object. +(blurb2.time = Time.now) + +### Object variables +Object variables are the same variables you're using for accessors, but __inside__ the object. +(@time = Time.now) diff --git a/translations/fr/try_ruby_530.md b/translations/fr/try_ruby_530.md new file mode 100644 index 00000000..85e2e25e --- /dev/null +++ b/translations/fr/try_ruby_530.md @@ -0,0 +1,46 @@ +--- +lang: EN +title: Your Own Turf +answer: Blurbalizer: +ok: My app created +error: +load: class Blurb;attr_accessor :content,:time,:mood;def initialize(mood, content="");@time=Time.now;@content=content[0..39];@mood=mood;end;end +--- + +Okay, let's wrap things up, kid. Here's the last chapter of the GRIPPING epic story of Try Ruby! +Now that you've got a taste of how it all works, how are you going to use it around the house +and in your grocer's freezer? +You're a great person (one of my favorites), but you need guidance. + +### Let's finish your app +You have app entries, but no actual app. +It still needs a title, someplace to store all BlurbsTM and a timeline in order to work. + +Guess what, we're going to use another class. I've given all the code for the new class in one go. +Just __take your time__ to study it. +I'm in no hurry, I'll wait for you in the next lesson. + + class Blurbalizer + def initialize(title) + @title = title + @blurbs = [] # A fresh clean array + # for storing Blurbs + end + + def add_a_blurb(mood, content) + # The << means add to the end of the array + @blurbs << Blurb.new(mood, content) + end + + def show_timeline + puts "Blurbify: #{@title} has #{@blurbs.count} Blurbs" + + @blurbs.sort_by { |t| + t.time + }.reverse.each { |t| + puts "#{t.content.ljust(40)} #{t.time}" + } + end + end + + myapp = Blurbalizer.new "The Big Blurb" diff --git a/translations/fr/try_ruby_540.md b/translations/fr/try_ruby_540.md new file mode 100644 index 00000000..7b756365 --- /dev/null +++ b/translations/fr/try_ruby_540.md @@ -0,0 +1,24 @@ +--- +lang: EN +title: What's that Blurb all about? +answer: Today +ok: Bring on the blurbs +error: +load: prev;class Blurbalizer;attr_reader :title;def initialize(title);@title=title;@blurbs=[];end;def add_a_blurb(mood, content);@blurbs << Blurb.new(mood, content);@blurbs.each {|t| t.time -= 73};end;def show_timeline;puts "Blurbalizer: #{@title} has #{@blurbs.count} Blurbs\n";@blurbs.sort_by { |t| t.time}.reverse.each { |t| puts "#{t.content.ljust(40)} #{t.time}"};end;end;myapp = Blurbalizer.new "The Big Blurb";myapp.add_a_blurb :sick,"Today Mount Hood Was Stolen!";myapp.add_a_blurb :confused,"I can not believe Mt. Hood was stolen!";myapp.add_a_blurb :dazed,"I am speechless!";myapp.add_a_blurb :mad,"It was stolen by a giraffe !!";myapp.add_a_blurb :sad,"I Left my Hoodie on the Mountain!";myapp.add_a_blurb :mad,"I am never going back to that mountain." +--- + +There you are. Did you figure out what all that code in the BlurbalizerTM class does ? + +> In the BlurbalizerTM class are two __methods__ (add\_a\_blurb and show\_timeline). +> You can use a method outside the class, just like we did with accessors. + +Time to start using BlurbalizerTM. I've already loaded some BlurbsTM for you, +but feel free to add your own. + +We're no longer creating BlurbsTM directly, but we use the add\_a\_blurb __method__ of the +BlurbalizerTM class. This way we can be sure all our BlurbsTM are stored in the +myapp object. + + myapp.add_a_blurb :moody, "Add Blurb here" + + myapp.show_timeline diff --git a/translations/fr/try_ruby_550.md b/translations/fr/try_ruby_550.md new file mode 100644 index 00000000..c23462f1 --- /dev/null +++ b/translations/fr/try_ruby_550.md @@ -0,0 +1,64 @@ +--- +lang: EN +title: It's All About Combining +answer: :- +ok: Moody ! +error: +load: prev +--- + +Some beautiful things can be done with the simple parts of Ruby, especially when you combine them +together into new things. +Here we've got an app made of a class containing another class. And, actually, Ruby really does good +with this kind of creature. It is called object oriented programming. + +We have arrived at the __last programming excercise__ of TryRuby. If you want, you can add some +more features to BlurbalizerTM. + +Maybe you want to print the mood as a smiley in the __show_timeline__ method. You could add +a _moodify_ method to the BlurbTM class and then use that method in the _show\_timeline_ method: + + class Blurb + attr_accessor :content, :time, :mood + + def initialize(mood, content="") + @time = Time.now + @content = content[0..39] + @mood = mood + end + + def moodify + if @mood == :sad + return ":-(" + elsif @mood == :happy + return ":-)" + # Add other moods here + end + + # The default mood + ":-|" + end + end + + class Blurbalizer + def initialize(title) + @title = title + @blurbs = [] + end + + def add_a_blurb(mood, content) + @blurbs << Blurb.new(mood, content) + end + + def show_timeline + puts "Blurbalizer: #{@title} has #{@blurbs.count} Blurbs" + + @blurbs.sort_by { |t| + t.time + }.reverse.each { |t| + puts "#{t.content.ljust(40)} #{t.time}" + } + end + end + + myapp.show_timeline diff --git a/translations/fr/try_ruby_560.md b/translations/fr/try_ruby_560.md new file mode 100644 index 00000000..746e124b --- /dev/null +++ b/translations/fr/try_ruby_560.md @@ -0,0 +1,31 @@ +--- +lang: EN +title: Summary #8, The Hey-Relax-You-Did-Good Summary +answer: +class: stretcher chapmark +ok: +error: +load: def ruby(f);puts "Go to www.ruby-lang.org to download Ruby";end;class K;attr_reader :rb;end;my_first_progam=K.new +--- + +This last section took a moment to wind down, to give you some pointers as to how you can use Ruby. + +If you enjoyed yourself, you can continue with the TryRuby Playground +or download and install Ruby: +ruby-lang.org + +Once you have Ruby installed, you can create a file, let say _my\_first\_progam.rb_, with a text +editor, type some Ruby code and then run it by opening a command prompt and typing: + + ruby my_first_progam.rb + +There are many (free) development tools available that combine an editor, file browser and a +'ruby-runner'. + +## Celebrate +You really deserve a double-layer cake with double-double frosting and a guy playing one of those guitars that's a double guitar. +I mean you finished, you really did! No doubt about it, you're a __certified red-blooded smartiac!__ + +## More info +There are a couple of articles on this website. They can give you some pointers on where to +go from here. diff --git a/translations/fr/try_ruby_60.md b/translations/fr/try_ruby_60.md new file mode 100644 index 00000000..c35a67c0 --- /dev/null +++ b/translations/fr/try_ruby_60.md @@ -0,0 +1,16 @@ +--- +lang: EN +title: Say Your Name Backwards +answer: \w+ +ok: dooG +error: +--- + +A string is a set of characters the computer can process. Imagine the letters are on a string of +laundry line and the quotes are clothespins holding the ends. The quotes mark the beginning and end. + +To reverse your name, type: + + "Jimmy".reverse + +(Don't forget the dot!) diff --git a/translations/fr/try_ruby_70.md b/translations/fr/try_ruby_70.md new file mode 100644 index 00000000..21cc4912 --- /dev/null +++ b/translations/fr/try_ruby_70.md @@ -0,0 +1,13 @@ +--- +lang: EN +title: Counting the Letters +answer: ^\d+$ +ok: Yep. Length is also a 'method' +error: +--- + +You have used the reverse __method__ on your name! By enclosing your name in quotes, you made a string. Then you called the reverse method, which works on strings to flip all the letters backwards. + +Now, let us see how many letters are in your name: + + "Jimmy".length diff --git a/translations/fr/try_ruby_80.md b/translations/fr/try_ruby_80.md new file mode 100644 index 00000000..94ac396d --- /dev/null +++ b/translations/fr/try_ruby_80.md @@ -0,0 +1,17 @@ +--- +lang: EN +title: On Repeat +answer: (\w+) +ok: Nice to meet you.Nice to meet you.Nice to meet you. +error: +--- + +Now, you're probably wondering what any of this is good for. + +Well, I'm sure you've been to a website that screamed, __Hey, your password is too short!__ + +See, some programs use that simple __.length__ code. + +Watch this. Let's multiply your name by 5. + + "Jimmy" * 5 diff --git a/translations/fr/try_ruby_90.md b/translations/fr/try_ruby_90.md new file mode 100644 index 00000000..624cc902 --- /dev/null +++ b/translations/fr/try_ruby_90.md @@ -0,0 +1,30 @@ +--- +lang: EN +title: Hey, Summary #1 Already +answer: ^NoMethodError(.*)$ +class: stretcher chapmark +ok: Nope, it is not possible to reverse a number. Click 'next' +error: +--- + +Let's look at what you've learned in the first minute. + +### The editor +Typing code into the editor and clicking on run gives you an answer in the ouput window. +(Almost) all code gives an answer. + +### Numbers and strings +Numbers and strings are Ruby's math and text objects. + +### Methods +You've used English-language methods like reverse and length. And symbolic methods like the +multiplication method: \* +__Methods mean action!__ + +This is the essence of your learning. Taking simple things, toying with them and turning them into +new things. Feeling comfortable yet? I promise you are. + +## Okay, +let's do something uncomfortable. Try reversing a number: + + 40.reverse