From a7e4f90482038df1466d4d080bba81f660643717 Mon Sep 17 00:00:00 2001 From: iMassim0 Date: Mon, 9 Apr 2018 13:26:11 +0200 Subject: [PATCH 1/5] Exo 1 2 3 faits --- 00_hello/hello.rb | 11 +++++++++++ 01_temperature/temperature.rb | 10 ++++++++++ 02_calculator/calculator.rb | 31 +++++++++++++++++++++++++++++++ 02_calculator/calculator_spec.rb | 4 ++-- 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/00_hello/hello.rb b/00_hello/hello.rb index 251797306..59c1d32e2 100644 --- a/00_hello/hello.rb +++ b/00_hello/hello.rb @@ -1 +1,12 @@ #write your code here +def hello + return "Hello!" +end + +hello() + +def greet(person) + return "Hello, #{person}!" +end + +greet("Alice") diff --git a/01_temperature/temperature.rb b/01_temperature/temperature.rb index 251797306..05cdbaee2 100644 --- a/01_temperature/temperature.rb +++ b/01_temperature/temperature.rb @@ -1 +1,11 @@ #write your code here + +def ftoc(f) + return (((f-32)*5)/9) +end + +def ctof((c)) + return ((((c.to_f)*9)/5)+32) +end + +puts ctof(37) diff --git a/02_calculator/calculator.rb b/02_calculator/calculator.rb index 251797306..a92aaf2ff 100644 --- a/02_calculator/calculator.rb +++ b/02_calculator/calculator.rb @@ -1 +1,32 @@ #write your code here + +def add(a, b) + return a + b +end + +def subtract(c, d) + return (c - d) +end + +def sum(f) + g = 0 + f.each do |e| + g += e + end + return g +end + +puts sum([]) + +puts sum([1,3,5,7,9]) + +def multiply(h) + i = 1 + h.each do |j| + i *= j + end + return i +end + +puts multiply([1, 2, 3]) + diff --git a/02_calculator/calculator_spec.rb b/02_calculator/calculator_spec.rb index fef7e9d00..a9fc9b427 100644 --- a/02_calculator/calculator_spec.rb +++ b/02_calculator/calculator_spec.rb @@ -77,12 +77,12 @@ # once the above tests pass, # write tests and code for the following: -describe "#multiply" do +describe "multiply" do it "multiplies two numbers" it "multiplies several numbers" - + end describe "#power" do From 860d971e20d79d00ff48985808b2045f40a0886f Mon Sep 17 00:00:00 2001 From: iMassim0 Date: Mon, 9 Apr 2018 16:11:23 +0200 Subject: [PATCH 2/5] MAJ exo 00 01 02 03 --- 03_simon_says/simon_says.rb | 70 ++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/03_simon_says/simon_says.rb b/03_simon_says/simon_says.rb index 251797306..5221b653d 100644 --- a/03_simon_says/simon_says.rb +++ b/03_simon_says/simon_says.rb @@ -1 +1,69 @@ -#write your code here +#write your code + +def echo(s) + return s +end + +def shout(h) + return h.upcase +end + +def repeat(c, p = 0) + o = Array.new + if p == 0 + o = c + " " + c + return o + else + p.times do + o << c + end + return (o.join(" ")) + end +end + +# puts repeat("cucu", 3) + +# puts "OH YEAH" + +def start_of_word(a, b = 0) + c = "" + if b == 0 + return a.chars[b] + elsif b != 0 + b.times do |i| + c << a.chars[i] + end + return c + end +end + +# puts start_of_word("KILO") +# puts start_of_word("SUZY", 4) + +def first_word(a) + return (a.split(" "))[0] +end + +# puts first_word("Hello to the queen") + + +def titleize(l) + little_words = ["or", "and", "the", "over"] + p = [] + a = l.split(" ") + p << l.split(" ")[0].capitalize! + a.slice!(0) + # puts a + # puts p + a.each do |k| + if little_words.include? k + p << k + else + p << k.capitalize! + end + end + + return p.join(" ") +end + +puts titleize("or biche or biche") From 80be7aa63fa17f4144bf964eb67cd5e27b83a193 Mon Sep 17 00:00:00 2001 From: iMassim0 Date: Mon, 9 Apr 2018 17:39:55 +0200 Subject: [PATCH 3/5] MAJ EXO 00 01 02 03 04 DONE --- 04_pig_latin/pig_latin.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/04_pig_latin/pig_latin.rb b/04_pig_latin/pig_latin.rb index 251797306..2b8d75bb7 100644 --- a/04_pig_latin/pig_latin.rb +++ b/04_pig_latin/pig_latin.rb @@ -1 +1,35 @@ #write your code here + +def translate(w) + + vowel = ["a","e","i","o","u"] + ay = "ay" + + if w.split(" ").length == 1 + return w[3..-1] + w[0..2] + ay if !(vowel.include? w[0]) && !(vowel.include? w[1]) && !(vowel.include? w[2]) || !(vowel.include? w[0]) && !(vowel.include? w[1]) && w[2] == vowel[4] + return w[2..-1] + w[0..1] + ay if !(vowel.include? w[0]) && !(vowel.include? w[1]) || !(vowel.include? w[0]) && w[1] == vowel[4] + return w[1..-1] + w[0] + ay if !(vowel.include? w[0]) && (vowel.include? w[1]) && w[1] != vowel[4] + return w + ay if (vowel.include? w[0]) + + elsif w.split(" ").length > 1 + chain = [] + w.split(" ").each do |k| + chain << k[3..-1] + k[0..2] + ay if !(vowel.include? k[0]) && !(vowel.include? k[1]) && !(vowel.include? k[2]) || !(vowel.include? k[0]) && !(vowel.include? k[1]) && k[2] == vowel[4] + chain << k[2..-1] + k[0..1] + ay if !(vowel.include? k[0]) && !(vowel.include? k[1]) || !(vowel.include? k[0]) && k[1] == vowel[4] + chain << k[1..-1] + k[0] + ay if !(vowel.include? k[0]) && (vowel.include? k[1]) && k[1] != vowel[4] + chain << k + ay if (vowel.include? k[0]) + end + return chain.join(" ") + end +end + +# puts translate("apple") # appleay +# puts translate("banana") # ananabay +# puts translate("cherry") # errychay +# puts translate("eat pie") # eatay iepay +# puts translate("three") # eethray +# puts translate("school") # oolschay +# puts translate("quiet") # ietquay +# puts translate("square") # aresquay +# puts translate("the quick brown fox") # ethay ickquay ownbray oxfay + From 58406190bfe1b9f88ca16e6c5fbd984077686e36 Mon Sep 17 00:00:00 2001 From: iMassim0 Date: Mon, 9 Apr 2018 21:01:15 +0200 Subject: [PATCH 4/5] Finish EXO 00 01 02 03 04 05 --- 05_book_titles/book.rb | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/05_book_titles/book.rb b/05_book_titles/book.rb index 009f2643e..52352de8b 100644 --- a/05_book_titles/book.rb +++ b/05_book_titles/book.rb @@ -1,3 +1,58 @@ class Book # write your code here + + attr_accessor :title + + def title=(new) + + little_words = ["or", "and", "the", "over", "in", "of", "a", "an"] + je_en = ["i"] + + if new.split(" ").length > 1 + + titCAP = [] + + tempo = new.split(" ") + + i = 0 + + tempo.each do |k| + + titCAP << k if Integer(k) rescue false + + if tempo[0] == k + titCAP << k.capitalize! + + elsif je_en.include? k + titCAP << k.capitalize! + + elsif little_words.include? k + titCAP << k + + else + titCAP << k.capitalize! + # puts titCAP.join(".") + end + + tempo.drop(i) + i += 1 + end + + @title = (titCAP.join(" ")).chomp(" ") + + else + + return @title = new.capitalize! + + end + + end + end + +temp = Book.new + +puts temp.title = "the i wish i knew the when i was 20" + +puts temp.title + From a7443bc92ef2285f10b02c52ca80ad09182c27d2 Mon Sep 17 00:00:00 2001 From: iMassim0 Date: Mon, 9 Apr 2018 22:22:06 +0200 Subject: [PATCH 5/5] MAJ README.md + verif 00/01/02/03/04/05 on rake -> ok --- README.md | 54 ++++++------------------------------------------------ 1 file changed, 6 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 7e7616724..501c9596d 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,11 @@ -Test First Ruby -- RSpec 3 Edition -========== - -### Set up instructions - -1. Fork this repo -2. Clone your version of the repo to your local machine -3. On your local machine, `cd` into the root folder of this repo in your terminal -4. run `bundle install` to install all the gems this project needs. - -### Getting started with the exercises - -To work through the first exercise, follow this process - -1. `cd` into `00_hello` from the root folder of this project -2. Run `rake`, to run the tests. It will fail with the following error: - ``` - Failures: - - 1) the hello function says hello - Failure/Error: expect(hello).to eq("Hello!") +Exercice THP - Semaine 2 - Jour 6 - Ruby - NameError: - undefined local variable or method `hello' for # - # ./00_hello/hello_spec.rb:106:in `block (2 levels) in ' - ``` -3. If the test fails to run and you get a `rake aborted! No Rakefile found` or any other error message not like the one above ensure that your working directory (`pwd` to see the path) contains no spaces as this is a common mistake made by people new to Rspec. -3. Read the failure output carefully and write the code that will make it pass -4. Run the tests again with `rake` -5. This will output that one test has passed and another test failure, write the code to make the next test pass. -4. Continue this process until all tests pass (when they are green) you have now completed the exercise. -5. Do this for all the exercises in this project -5. To get hints and tips about each exercise, view the `index.html` file that is included in each exercise folder - - -Basically, this is "error-driven development"... you'll keep running tests, hitting error messages, fixing those messages, running more tests... It is meant to not only test your Ruby skills but also get you comfortable seeing big scary looking stack traces and error messages. Most of the development you do at first will be just like this. In fact, most of *all* development is error-driven. So get comfortable with it! - -### Troubleshooting - -* Don't name any of your directories with spaces in them! It will give you horribly frustrating error messages and code hates dealing with spaces. For instance: - - ```language-bash - # BAD: - /Documents/My Homework/ruby +========== - # GOOD: - /Documents/my_homework/ruby - ``` +Exercices en provenance de : https://github.com/felhix/learn_ruby +### Done by @Massimo Di Fleurio alias Maxime FLEURY -### Credit +### Partnership : @bab alias Baptiste ROGEON -This is forked from [https://github.com/alexch/learn_ruby](https://github.com/alexch/learn_ruby), its original creator. +## TEAM_THP_BDX