Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions 00_hello/hello.rb
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
#write your code here
def hello
return "Hello!"
end

hello()

def greet(person)
return "Hello, #{person}!"
end

greet("Alice")
10 changes: 10 additions & 0 deletions 01_temperature/temperature.rb
Original file line number Diff line number Diff line change
@@ -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)
31 changes: 31 additions & 0 deletions 02_calculator/calculator.rb
Original file line number Diff line number Diff line change
@@ -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])

4 changes: 2 additions & 2 deletions 02_calculator/calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
70 changes: 69 additions & 1 deletion 03_simon_says/simon_says.rb
Original file line number Diff line number Diff line change
@@ -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")
34 changes: 34 additions & 0 deletions 04_pig_latin/pig_latin.rb
Original file line number Diff line number Diff line change
@@ -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

55 changes: 55 additions & 0 deletions 05_book_titles/book.rb
Original file line number Diff line number Diff line change
@@ -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

54 changes: 6 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 #<RSpec::ExampleGroups::TheHelloFunction:0x007fa1221408f0>
# ./00_hello/hello_spec.rb:106:in `block (2 levels) in <top (required)>'
```
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