diff --git a/RubyProject/bin/learn_couleurs_game b/RubyProject/bin/learn_couleurs_game new file mode 100755 index 0000000..a743bd5 --- /dev/null +++ b/RubyProject/bin/learn_couleurs_game @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby + +require 'learn_couleurs_game' diff --git a/RubyProject/doc/LearnCouleurs.html b/RubyProject/doc/LearnCouleurs.html new file mode 100644 index 0000000..e860360 --- /dev/null +++ b/RubyProject/doc/LearnCouleurs.html @@ -0,0 +1,567 @@ + + + + + + +class LearnCouleurs - RDoc Documentation + + + + + + + + + + + + + + + + +
+

class LearnCouleurs

+ +
+ +
+ + + + +
+ + + + + + + + +
+

Attributes

+ + +
+
+ current_couleur[RW] +
+ +
+ + + +
+
+ +
+
+ over[RW] +
+ +
+ + + +
+
+ +
+
+ player[RW] +
+ +
+ + + +
+
+ +
+
+ score[RW] +
+ +
+ + + +
+
+ +
+ + + + +
+

Public Class Methods

+ + +
+ +
+ new() + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/learn_couleurs_game/learn_couleurs.rb, line 5
+def initialize
+  @player = ""
+  @couleurs = { 40 => "noir", 41 => "rouge", 42 => "vert", 43 => "jaune", 44 => "bleu", 47 => "gris"
+  }
+  @current_couleur = 0
+  @over = false
+  @rounds = -1
+  @score = 0
+  @max_rounds = 5
+end
+
+ +
+ + + + +
+ + +
+ +
+

Public Instance Methods

+ + +
+ +
+ comment_final_score() + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/learn_couleurs_game/learn_couleurs.rb, line 68
+def comment_final_score
+  if @rounds == -1
+    puts "Essaie de jouer maintenant!"
+  elsif @score < 0
+    puts "CATASTROPHE!!!"
+  elsif @score < @max_rounds/2
+    puts "MOUAIS..."
+  elsif @score < @max_rounds*3/4
+    puts "BIEN!"
+  elsif @score < @max_rounds
+    puts "TRES BIEN!"
+  else
+    puts "PARFAIT!!!"
+  end
+end
+
+ +
+ + + + +
+ + +
+ +
+ display_couleurs() + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/learn_couleurs_game/learn_couleurs.rb, line 32
+def display_couleurs
+  puts "Liste couleurs:"
+  @couleurs.each { |key, value| print "   \0033["+key.to_s+"m   \0033[0m" + ' = ' + value + "\n\n" }
+  @over = true
+end
+
+ +
+ + + + +
+ + +
+ +
+ display_new_color() + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/learn_couleurs_game/learn_couleurs.rb, line 45
+def display_new_color
+  @current_couleur = @couleurs.keys.sample
+  puts "Quelle couleur?"
+  couleur_code = "   \0033["+@current_couleur.to_s+"m   \0033[0m\n"
+  puts couleur_code
+end
+
+ +
+ + + + +
+ + +
+ +
+ display_score() + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/learn_couleurs_game/learn_couleurs.rb, line 64
+def display_score
+  puts "Score: "+@score.to_s+"/"+@max_rounds.to_s
+end
+
+ +
+ + + + +
+ + +
+ +
+ over?() + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/learn_couleurs_game/learn_couleurs.rb, line 38
+def over?
+  if @rounds == @max_rounds
+    @over = true
+  end
+  @over
+end
+
+ +
+ + + + +
+ + +
+ +
+ player_answer() + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/learn_couleurs_game/learn_couleurs.rb, line 52
+def player_answer
+  answer = gets.chomp
+  until answer == @couleurs[@current_couleur]
+   puts "Oh non! Essaie encore:\n\n"
+   @score-=1
+   answer = gets.chomp
+  end
+   puts "Bravo!\n\n"
+   @score+=1
+   @rounds+=1
+end
+
+ +
+ + + + +
+ + +
+ +
+ selection() + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/learn_couleurs_game/learn_couleurs.rb, line 20
+def selection
+  puts "Reviser(r) ou Commencer(c)?"
+  selection = gets.chomp
+  if selection == "r"
+      display_couleurs
+  elsif selection == "c"
+      @rounds +=1
+  else
+      abort("Invalide")
+  end
+end
+
+ +
+ + + + +
+ + +
+ +
+ welcome_player() + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/learn_couleurs_game/learn_couleurs.rb, line 16
+def welcome_player
+  welcome = "Bienvenue "+ @player + "\n\n"
+end
+
+ +
+ + + + +
+ + +
+ +
+ +
+ + + + diff --git a/RubyProject/doc/created.rid b/RubyProject/doc/created.rid new file mode 100644 index 0000000..3ff8278 --- /dev/null +++ b/RubyProject/doc/created.rid @@ -0,0 +1,8 @@ +Tue, 10 Dec 2013 17:34:38 -0800 +./bin/learn_couleurs_game Tue, 10 Dec 2013 01:13:55 -0800 +./doc/created.rid Tue, 10 Dec 2013 17:34:38 -0800 +./learn_couleurs_game-0.0.0.gem Tue, 10 Dec 2013 00:57:16 -0800 +./learn_couleurs_game-0.0.1.gem Tue, 10 Dec 2013 01:25:35 -0800 +./learn_couleurs_game.gemspec Tue, 10 Dec 2013 01:24:59 -0800 +./lib/learn_couleurs_game/learn_couleurs.rb Mon, 09 Dec 2013 22:58:29 -0800 +./lib/learn_couleurs_game.rb Tue, 10 Dec 2013 01:21:14 -0800 diff --git a/RubyProject/doc/doc/created_rid.html b/RubyProject/doc/doc/created_rid.html new file mode 100644 index 0000000..013d0fb --- /dev/null +++ b/RubyProject/doc/doc/created_rid.html @@ -0,0 +1,85 @@ + + + + + + +created.rid - RDoc Documentation + + + + + + + + + + + + + + + + +
+ +
+ + + + + diff --git a/RubyProject/doc/images/add.png b/RubyProject/doc/images/add.png new file mode 100644 index 0000000..6332fef Binary files /dev/null and b/RubyProject/doc/images/add.png differ diff --git a/RubyProject/doc/images/arrow_up.png b/RubyProject/doc/images/arrow_up.png new file mode 100644 index 0000000..1ebb193 Binary files /dev/null and b/RubyProject/doc/images/arrow_up.png differ diff --git a/RubyProject/doc/images/brick.png b/RubyProject/doc/images/brick.png new file mode 100644 index 0000000..7851cf3 Binary files /dev/null and b/RubyProject/doc/images/brick.png differ diff --git a/RubyProject/doc/images/brick_link.png b/RubyProject/doc/images/brick_link.png new file mode 100644 index 0000000..9ebf013 Binary files /dev/null and b/RubyProject/doc/images/brick_link.png differ diff --git a/RubyProject/doc/images/bug.png b/RubyProject/doc/images/bug.png new file mode 100644 index 0000000..2d5fb90 Binary files /dev/null and b/RubyProject/doc/images/bug.png differ diff --git a/RubyProject/doc/images/bullet_black.png b/RubyProject/doc/images/bullet_black.png new file mode 100644 index 0000000..5761970 Binary files /dev/null and b/RubyProject/doc/images/bullet_black.png differ diff --git a/RubyProject/doc/images/bullet_toggle_minus.png b/RubyProject/doc/images/bullet_toggle_minus.png new file mode 100644 index 0000000..b47ce55 Binary files /dev/null and b/RubyProject/doc/images/bullet_toggle_minus.png differ diff --git a/RubyProject/doc/images/bullet_toggle_plus.png b/RubyProject/doc/images/bullet_toggle_plus.png new file mode 100644 index 0000000..9ab4a89 Binary files /dev/null and b/RubyProject/doc/images/bullet_toggle_plus.png differ diff --git a/RubyProject/doc/images/date.png b/RubyProject/doc/images/date.png new file mode 100644 index 0000000..783c833 Binary files /dev/null and b/RubyProject/doc/images/date.png differ diff --git a/RubyProject/doc/images/delete.png b/RubyProject/doc/images/delete.png new file mode 100644 index 0000000..08f2493 Binary files /dev/null and b/RubyProject/doc/images/delete.png differ diff --git a/RubyProject/doc/images/find.png b/RubyProject/doc/images/find.png new file mode 100644 index 0000000..1547479 Binary files /dev/null and b/RubyProject/doc/images/find.png differ diff --git a/RubyProject/doc/images/loadingAnimation.gif b/RubyProject/doc/images/loadingAnimation.gif new file mode 100644 index 0000000..82290f4 Binary files /dev/null and b/RubyProject/doc/images/loadingAnimation.gif differ diff --git a/RubyProject/doc/images/macFFBgHack.png b/RubyProject/doc/images/macFFBgHack.png new file mode 100644 index 0000000..c6473b3 Binary files /dev/null and b/RubyProject/doc/images/macFFBgHack.png differ diff --git a/RubyProject/doc/images/package.png b/RubyProject/doc/images/package.png new file mode 100644 index 0000000..da3c2a2 Binary files /dev/null and b/RubyProject/doc/images/package.png differ diff --git a/RubyProject/doc/images/page_green.png b/RubyProject/doc/images/page_green.png new file mode 100644 index 0000000..de8e003 Binary files /dev/null and b/RubyProject/doc/images/page_green.png differ diff --git a/RubyProject/doc/images/page_white_text.png b/RubyProject/doc/images/page_white_text.png new file mode 100644 index 0000000..813f712 Binary files /dev/null and b/RubyProject/doc/images/page_white_text.png differ diff --git a/RubyProject/doc/images/page_white_width.png b/RubyProject/doc/images/page_white_width.png new file mode 100644 index 0000000..1eb8809 Binary files /dev/null and b/RubyProject/doc/images/page_white_width.png differ diff --git a/RubyProject/doc/images/plugin.png b/RubyProject/doc/images/plugin.png new file mode 100644 index 0000000..6187b15 Binary files /dev/null and b/RubyProject/doc/images/plugin.png differ diff --git a/RubyProject/doc/images/ruby.png b/RubyProject/doc/images/ruby.png new file mode 100644 index 0000000..f763a16 Binary files /dev/null and b/RubyProject/doc/images/ruby.png differ diff --git a/RubyProject/doc/images/tag_blue.png b/RubyProject/doc/images/tag_blue.png new file mode 100644 index 0000000..3f02b5f Binary files /dev/null and b/RubyProject/doc/images/tag_blue.png differ diff --git a/RubyProject/doc/images/tag_green.png b/RubyProject/doc/images/tag_green.png new file mode 100644 index 0000000..83ec984 Binary files /dev/null and b/RubyProject/doc/images/tag_green.png differ diff --git a/RubyProject/doc/images/transparent.png b/RubyProject/doc/images/transparent.png new file mode 100644 index 0000000..d665e17 Binary files /dev/null and b/RubyProject/doc/images/transparent.png differ diff --git a/RubyProject/doc/images/wrench.png b/RubyProject/doc/images/wrench.png new file mode 100644 index 0000000..5c8213f Binary files /dev/null and b/RubyProject/doc/images/wrench.png differ diff --git a/RubyProject/doc/images/wrench_orange.png b/RubyProject/doc/images/wrench_orange.png new file mode 100644 index 0000000..565a933 Binary files /dev/null and b/RubyProject/doc/images/wrench_orange.png differ diff --git a/RubyProject/doc/images/zoom.png b/RubyProject/doc/images/zoom.png new file mode 100644 index 0000000..908612e Binary files /dev/null and b/RubyProject/doc/images/zoom.png differ diff --git a/RubyProject/doc/index.html b/RubyProject/doc/index.html new file mode 100644 index 0000000..c54159d --- /dev/null +++ b/RubyProject/doc/index.html @@ -0,0 +1,82 @@ + + + + + + +RDoc Documentation + + + + + + + + + + + + + + + + +
+

This is the API documentation for RDoc Documentation. +

+ + + + diff --git a/RubyProject/doc/js/darkfish.js b/RubyProject/doc/js/darkfish.js new file mode 100644 index 0000000..f26fd45 --- /dev/null +++ b/RubyProject/doc/js/darkfish.js @@ -0,0 +1,155 @@ +/** + * + * Darkfish Page Functions + * $Id: darkfish.js 53 2009-01-07 02:52:03Z deveiant $ + * + * Author: Michael Granger + * + */ + +/* Provide console simulation for firebug-less environments */ +if (!("console" in window) || !("firebug" in console)) { + var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", + "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"]; + + window.console = {}; + for (var i = 0; i < names.length; ++i) + window.console[names[i]] = function() {}; +}; + + +/** + * Unwrap the first element that matches the given @expr@ from the targets and return them. + */ +$.fn.unwrap = function( expr ) { + return this.each( function() { + $(this).parents( expr ).eq( 0 ).after( this ).remove(); + }); +}; + + +function showSource( e ) { + var target = e.target; + var codeSections = $(target). + parents('.method-detail'). + find('.method-source-code'); + + $(target). + parents('.method-detail'). + find('.method-source-code'). + slideToggle(); +}; + +function hookSourceViews() { + $('.method-heading').click( showSource ); +}; + +function toggleDebuggingSection() { + $('.debugging-section').slideToggle(); +}; + +function hookDebuggingToggle() { + $('#debugging-toggle img').click( toggleDebuggingSection ); +}; + +function hookTableOfContentsToggle() { + $('.indexpage li .toc-toggle').each( function() { + $(this).click( function() { + $(this).toggleClass('open'); + }); + + var section = $(this).next(); + + $(this).click( function() { + section.slideToggle(); + }); + }); +} + +function hookSearch() { + var input = $('#search-field').eq(0); + var result = $('#search-results').eq(0); + $(result).show(); + + var search_section = $('#search-section').get(0); + $(search_section).show(); + + var search = new Search(search_data, input, result); + + search.renderItem = function(result) { + var li = document.createElement('li'); + var html = ''; + + // TODO add relative path to + + + + + + + + + + + + +
+ +

Gem::Specification.new do |s| s.name = 'learn_couleurs_game' +s.version = '0.0.1' s.date = '2013-12-08' s.summary = +“Project for Ruby Class” s.description = “A gem to learn the names of +colors in French” s.authors = [“Alicia French”] s.email = +'alienor18@yahoo.com' s.homepage = 'rubygems.org/gems/learn_couleurs_game' +s.files = +['lib/learn_couleurs_game.rb','lib/learn_couleurs_game/learn_couleurs.rb'] +s.executables << 'learn_couleurs_game' end

+ +
+ + + + + diff --git a/RubyProject/doc/rdoc.css b/RubyProject/doc/rdoc.css new file mode 100644 index 0000000..3520703 --- /dev/null +++ b/RubyProject/doc/rdoc.css @@ -0,0 +1,595 @@ +/* + * "Darkfish" Rdoc CSS + * $Id: rdoc.css 54 2009-01-27 01:09:48Z deveiant $ + * + * Author: Michael Granger + * + */ + +/* vim: ft=css et sw=2 ts=2 sts=2 */ +/* Base Green is: #6C8C22 */ + +* { padding: 0; margin: 0; } + +body { + background: #efefef; + font: 14px "Helvetica Neue", Helvetica, Tahoma, sans-serif; + margin-left: 40px; +} +body.file-popup { + font-size: 90%; + margin-left: 0; +} + +h1 { + font-size: 300%; + text-shadow: rgba(135,145,135,0.65) 2px 2px 3px; + color: #6C8C22; +} +h2,h3,h4 { margin-top: 1.5em; } + +h1 span, +h2 span, +h3 span, +h4 span, +h5 span, +h6 span { + display: none; + padding-left: 1em; + font-size: 50%; + vertical-align: super; +} + +h1:hover span, +h2:hover span, +h3:hover span, +h4:hover span, +h5:hover span, +h6:hover span { + display: inline; +} + +:link, +:visited { + color: #6C8C22; + text-decoration: none; +} +:link:hover, +:visited:hover { + border-bottom: 1px dotted #6C8C22; +} + +pre { + background: #ddd; + padding: 0.5em 0; +} + +blockquote { + background: #ddd; + margin: 1em; + padding: 0.25em; +} + +blockquote > :first-child { + margin-top: 0 !important; +} + +/* @group Generic Classes */ + +.initially-hidden { + display: none; +} + +#search-field { + width: 98%; + background: #eee; + border: none; + height: 1.5em; + -webkit-border-radius: 4px; +} +#search-field:focus { + background: #f1edba; +} +#search-field:-moz-placeholder, +#search-field::-webkit-input-placeholder { + font-weight: bold; + color: #666; +} + +.missing-docs { + font-size: 120%; + background: white url(images/wrench_orange.png) no-repeat 4px center; + color: #ccc; + line-height: 2em; + border: 1px solid #d00; + opacity: 1; + padding-left: 20px; + text-indent: 24px; + letter-spacing: 3px; + font-weight: bold; + -webkit-border-radius: 5px; + -moz-border-radius: 5px; +} + +.target-section { + border: 2px solid #dcce90; + border-left-width: 8px; + padding: 0 1em; + background: #fff3c2; +} + +/* @end */ + +/* @group Index Page, Standalone file pages */ +.indexpage ul { + line-height: 160%; + list-style: none; +} +.indexpage ul :link, +.indexpage ul :visited { + font-size: 16px; +} + +.indexpage li { + padding-left: 20px; +} + +.indexpage ul > li { + background: url(images/bullet_black.png) no-repeat left 4px; +} +.indexpage li.method { + background: url(images/plugin.png) no-repeat left 4px; +} +.indexpage li.module { + background: url(images/package.png) no-repeat left 4px; +} +.indexpage li.class { + background: url(images/ruby.png) no-repeat left 4px; +} +.indexpage li.file { + background: url(images/page_white_text.png) no-repeat left 4px; +} +.indexpage li li { + background: url(images/tag_blue.png) no-repeat left 4px; +} +.indexpage li .toc-toggle { + width: 16px; + height: 16px; + background: url(images/add.png) no-repeat; +} + +.indexpage li .toc-toggle.open { + background: url(images/delete.png) no-repeat; +} + +/* @end */ + +/* @group Top-Level Structure */ + +#metadata { + float: left; + width: 260px; +} + +#documentation { + margin: 2em 1em 5em 300px; + min-width: 340px; +} + +#validator-badges { + clear: both; + margin: 1em 1em 2em; + font-size: smaller; +} + +/* @end */ + +/* @group Metadata Section */ +#metadata .section { + background-color: #dedede; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border: 1px solid #aaa; + margin: 0 8px 8px; + font-size: 90%; + overflow: hidden; +} +#metadata h3.section-header { + margin: 0; + padding: 2px 8px; + background: #ccc; + color: #666; + -moz-border-radius-topleft: 4px; + -moz-border-radius-topright: 4px; + -webkit-border-top-left-radius: 4px; + -webkit-border-top-right-radius: 4px; + border-bottom: 1px solid #aaa; +} +#metadata #home-section h3.section-header { + border-bottom: 0; +} + +#metadata ul, +#metadata dl, +#metadata p { + padding: 8px; + list-style: none; +} + +#file-metadata { + margin-top: 2em; +} + +#file-metadata ul { + padding-left: 28px; + list-style-image: url(images/page_green.png); +} + +#table-of-contents { + margin-top: 2em; +} + +#table-of-contents ul { + padding-left: 28px; + list-style-image: url(images/tag_blue.png); +} + +dl.svninfo { + color: #666; + margin: 0; +} +dl.svninfo dt { + font-weight: bold; +} + +ul.link-list li { + white-space: nowrap; + line-height: 20px; +} + +ul.link-list .type { + font-size: 8px; + text-transform: uppercase; + color: white; + background: #969696; + padding: 2px 4px; + -webkit-border-radius: 5px; +} + +.calls-super { + background: url(images/arrow_up.png) no-repeat right center; +} + +/* @end */ + +/* @group Class Metadata Section */ +#class-metadata { + margin-top: 2em; +} +/* @end */ + +/* @group Project Metadata Section */ +#project-metadata { + margin-top: 2em; +} + +#project-metadata .section { + border: 1px solid #aaa; +} +#project-metadata h3.section-header { + border-bottom: 1px solid #aaa; + position: relative; +} + +#project-metadata form { + color: #777; + background: #ccc; +} + +/* @end */ + +/* @group Documentation Section */ +.description { + font-size: 100%; + color: #333; +} + +.description p { + margin: 1em 0.4em; +} + +.description li p { + margin: 0; +} + +.description ol, +.description ul { + margin-left: 1.5em; +} +.description ol li, +.description ul li { + line-height: 1.4em; +} + +.note-list { + margin: 8px 0; +} + +.label-list { + margin: 8px 1.5em; + border: 1px solid #ccc; +} +.description .label-list { + font-size: 14px; +} + +.note-list dt { + font-weight: bold; +} +.note-list dd { + padding: 0 12px; +} + +.label-list dt { + padding: 2px 4px; + font-weight: bold; + background: #ddd; +} +.label-list dd { + padding: 2px 12px; +} +.label-list dd + dt, +.note-list dd + dt { + margin-top: 0.7em; +} + +#documentation .section { + font-size: 90%; +} + +#documentation h2.section-header { + margin-top: 1em; + padding: 0.25em 0.5em; + background: #ccc; + color: #333; + font-size: 175%; + border: 1px solid #bbb; + -moz-border-radius: 3px; + -webkit-border-radius: 3px; +} + +.documentation-section-title { + position: relative; +} +.documentation-section-title .section-click-top { + position: absolute; + top: 6px; + right: 12px; + font-size: 10px; + color: #9b9877; + visibility: hidden; + padding-right: 0.5px; +} + +.documentation-section-title:hover .section-click-top { + visibility: visible; +} + +#documentation h3.section-header { + margin-top: 1em; + padding: 0.25em 0.5em; + background-color: #dedede; + color: #333; + font-size: 150%; + border: 1px solid #bbb; + -moz-border-radius: 3px; + -webkit-border-radius: 3px; +} + +#constants-list > dl, +#attributes-list > dl { + margin: 1em 0 2em; + border: 0; +} +#constants-list > dl dt, +#attributes-list > dl dt { + padding-left: 0; + font-weight: bold; + font-family: Monaco, "Andale Mono"; + background: inherit; +} +#constants-list > dl dt a, +#attributes-list > dl dt a { + color: inherit; +} +#constants-list > dl dd, +#attributes-list > dl dd { + margin: 0 0 1em 0; + padding: 0; + color: #666; +} + +.documentation-section h2 { + position: relative; +} + +.documentation-section h2 a { + position: absolute; + top: 8px; + right: 10px; + font-size: 12px; + color: #9b9877; + visibility: hidden; +} + +.documentation-section h2:hover a { + visibility: visible; +} + +/* @group Method Details */ + +#documentation .method-source-code { + display: none; +} + +#documentation .method-description .method-calls-super { + color: #333; + font-weight: bolder; +} + +#documentation .method-detail { + margin: 0.5em 0; + padding: 0.5em 0; + cursor: pointer; +} +#documentation .method-detail:hover { + background-color: #f1edba; +} +#documentation .method-heading { + position: relative; + padding: 2px 4px 0 20px; + font-size: 125%; + font-weight: bold; + color: #333; + background: url(images/brick.png) no-repeat left bottom; +} +#documentation .method-heading :link, +#documentation .method-heading :visited { + color: inherit; +} +#documentation .method-click-advice { + position: absolute; + top: 2px; + right: 5px; + font-size: 10px; + color: #9b9877; + visibility: hidden; + padding-right: 20px; + line-height: 20px; + background: url(images/zoom.png) no-repeat right top; +} +#documentation .method-heading:hover .method-click-advice { + visibility: visible; +} + +#documentation .method-alias .method-heading { + color: #666; + background: url(images/brick_link.png) no-repeat left bottom; +} + +#documentation .method-description, +#documentation .aliases { + margin: 0 20px; + color: #666; +} + +#documentation .method-description p, +#documentation .aliases p { + line-height: 1.2em; +} + +#documentation .aliases { + padding-top: 4px; + font-style: italic; + cursor: default; +} +#documentation .method-description p { + margin-bottom: 0.5em; +} +#documentation .method-description ul { + margin-left: 1.5em; +} +pre { + margin: 0.5em 0; +} + +#documentation .attribute-method-heading { + background: url(images/tag_green.png) no-repeat left bottom; +} +#documentation #attribute-method-details .method-detail:hover { + background-color: transparent; + cursor: default; +} +#documentation .attribute-access-type { + font-size: 60%; + text-transform: uppercase; + vertical-align: super; + padding: 0 2px; +} +/* @end */ + +/* @end */ + +/* @group Source Code */ + +pre { + overflow: auto; + background: #262626; + color: white; + border: 1px dashed #999; + padding: 0.5em; +} + +.description pre { + margin: 0 0.4em; +} + +.ruby-constant { color: #7fffd4; background: transparent; } +.ruby-keyword { color: #00ffff; background: transparent; } +.ruby-ivar { color: #eedd82; background: transparent; } +.ruby-operator { color: #00ffee; background: transparent; } +.ruby-identifier { color: #ffdead; background: transparent; } +.ruby-node { color: #ffa07a; background: transparent; } +.ruby-comment { color: #dc0000; font-weight: bold; background: transparent; } +.ruby-regexp { color: #ffa07a; background: transparent; } +.ruby-value { color: #7fffd4; background: transparent; } + +/* @end */ + + +/* @group search results */ +#search-results h1 { + font-size: 1em; + font-weight: normal; + text-shadow: none; +} + +#search-results .current { + background: #ccc; + border-bottom: 1px solid transparent; +} + +#search-results li { + list-style: none; + border-bottom: 1px solid #aaa; + -moz-border-radius: 4px; + -webkit-border-radius: 4px; + border-radius: 4px; + margin-bottom: 0.5em; +} + +#search-results li:last-child { + border-bottom: none; + margin-bottom: 0; +} + +#search-results li p { + padding: 0; + margin: 0.5em; +} + +#search-results .search-namespace { + font-weight: bold; +} + +#search-results li em { + background: yellow; + font-style: normal; +} + +#search-results pre { + margin: 0.5em; +} + +/* @end */ + diff --git a/RubyProject/doc/table_of_contents.html b/RubyProject/doc/table_of_contents.html new file mode 100644 index 0000000..a5107d4 --- /dev/null +++ b/RubyProject/doc/table_of_contents.html @@ -0,0 +1,74 @@ + + + + + + +Table of Contents - RDoc Documentation + + + + + + + + + + + + + + +

Table of Contents - RDoc Documentation

+ +

Pages

+ + +

Classes/Modules

+ + +

Methods

+ + + + + diff --git a/RubyProject/learn_couleurs_game-0.0.0.gem b/RubyProject/learn_couleurs_game-0.0.0.gem new file mode 100644 index 0000000..6b9315d Binary files /dev/null and b/RubyProject/learn_couleurs_game-0.0.0.gem differ diff --git a/RubyProject/learn_couleurs_game-0.0.1.gem b/RubyProject/learn_couleurs_game-0.0.1.gem new file mode 100644 index 0000000..26470eb Binary files /dev/null and b/RubyProject/learn_couleurs_game-0.0.1.gem differ diff --git a/RubyProject/learn_couleurs_game-0.0.2.gem b/RubyProject/learn_couleurs_game-0.0.2.gem new file mode 100644 index 0000000..26b5de1 Binary files /dev/null and b/RubyProject/learn_couleurs_game-0.0.2.gem differ diff --git a/RubyProject/learn_couleurs_game.gemspec b/RubyProject/learn_couleurs_game.gemspec new file mode 100644 index 0000000..8ca4b8f --- /dev/null +++ b/RubyProject/learn_couleurs_game.gemspec @@ -0,0 +1,13 @@ +Gem::Specification.new do |s| +s.name = 'learn_couleurs_game' +s.version = '0.0.2' +s.date = '2013-12-10' +s.summary = "Project for Ruby Class" +s.description = "A gem to learn the names of colors in French" +s.authors = ["Alicia French"] +s.email = 'alienor18@yahoo.com' +s.homepage = 'http://rubygems.org/gems/learn_couleurs_game' +s.files = ['lib/learn_couleurs_game.rb','lib/learn_couleurs_game/learn_couleurs.rb'] +s.executables << 'learn_couleurs_game' +end + diff --git a/RubyProject/lib/learn_couleurs_game.rb b/RubyProject/lib/learn_couleurs_game.rb new file mode 100644 index 0000000..32af7c5 --- /dev/null +++ b/RubyProject/lib/learn_couleurs_game.rb @@ -0,0 +1,15 @@ +require 'learn_couleurs_game/learn_couleurs.rb' + +@game = LearnCouleurs.new +puts "What is your name?" +@game.player = gets.chomp +puts @game.welcome_player +@game.selection + +until @game.over? + @game.display_new_color + @game.player_answer + @game.display_score +end + @game.comment_final_score + diff --git a/RubyProject/lib/learn_couleurs_game/learn_couleurs.rb b/RubyProject/lib/learn_couleurs_game/learn_couleurs.rb new file mode 100644 index 0000000..5bec281 --- /dev/null +++ b/RubyProject/lib/learn_couleurs_game/learn_couleurs.rb @@ -0,0 +1,84 @@ +class LearnCouleurs + + attr_accessor :player,:score,:over,:current_couleur + + def initialize + @player = "" + @couleurs = { 40 => "noir", 41 => "rouge", 42 => "vert", 43 => "jaune", 44 => "bleu", 47 => "gris" + } + @current_couleur = 0 + @over = false + @rounds = -1 + @score = 0 + @max_rounds = 5 + end + + def welcome_player + welcome = "Bienvenue "+ @player + "\n\n" + end + + def selection + puts "Reviser(r) ou Commencer(c)?" + selection = gets.chomp + if selection == "r" + display_couleurs + elsif selection == "c" + @rounds +=1 + else + abort("Invalide") + end + end + + def display_couleurs + puts "Liste couleurs:" + @couleurs.each { |key, value| print " \033["+key.to_s+"m \033[0m" + ' = ' + value + "\n\n" } + @over = true + end + + def over? + if @rounds == @max_rounds + @over = true + end + @over + end + + def display_new_color + @current_couleur = @couleurs.keys.sample + puts "Quelle couleur?" + couleur_code = " \033["+@current_couleur.to_s+"m \033[0m\n" + puts couleur_code + end + + def player_answer + answer = gets.chomp + until answer == @couleurs[@current_couleur] + puts "Oh non! Essaie encore:\n\n" + @score-=1 + answer = gets.chomp + end + puts "Bravo!\n\n" + @score+=1 + @rounds+=1 + end + + def display_score + puts "Score: "+@score.to_s+"/"+@max_rounds.to_s + end + + def comment_final_score + if @rounds == -1 + puts "Essaie de jouer maintenant!" + elsif @score < 0 + puts "CATASTROPHE!!!" + elsif @score < @max_rounds/2 + puts "MOUAIS..." + elsif @score < @max_rounds*3/4 + puts "BIEN!" + elsif @score < @max_rounds + puts "TRES BIEN!" + else + puts "PARFAIT!!!" + end + end + +end diff --git a/week1/homework/questions.txt b/week1/homework/questions.txt index bd581a6..073fb47 100644 --- a/week1/homework/questions.txt +++ b/week1/homework/questions.txt @@ -3,13 +3,21 @@ Chapter 3 Classes, Objects, and Variables p.86-90 Strings (Strings section in Chapter 6 Standard Types) 1. What is an object? +An object is a class instance. 2. What is a variable? +A variable is a reference to an object. 3. What is the difference between an object and a class? +A class is like a model for things used in the application, and an object is what is created according to this model. 4. What is a String? +A String is a sequence of characters. It is an object of class String. 5. What are three messages that I can send to a string object? Hint: think methods +downcase, reverse, empty?. 6. What are two ways of defining a String literal? Bonus: What is the difference between the two? +A String literal can be defined with single quotes or double quotes. +Strings defined with single quotes can only use a limited number of escape sequences (backslash and single quote) but require less work from the interpreter, whereas strings defined with double quotes can handle a lot more escape sequences (/n, /t...). + diff --git a/week1/homework/strings_and_rspec_spec.rb b/week1/homework/strings_and_rspec_spec.rb index ea79e4c..57dc943 100644 --- a/week1/homework/strings_and_rspec_spec.rb +++ b/week1/homework/strings_and_rspec_spec.rb @@ -12,14 +12,15 @@ before(:all) do @my_string = "Renée is a fun teacher. Ruby is a really cool programming language" end - it "should be able to count the charaters" - it "should be able to split on the . charater" do - pending - result = #do something with @my_string here + it "should be able to count the charaters" do + @my_string.should have(66).characters + end + it "should be able to split on the . character" do + result = @my_string.split(".") result.should have(2).items end it "should be able to give the encoding of the string" do - pending 'helpful hint: should eq (Encoding.find("UTF-8"))' + "#{@my_string.encoding}".should eq "UTF-8" end end end diff --git a/week2/homework/questions.txt b/week2/homework/questions.txt index 939e42d..f6621a6 100644 --- a/week2/homework/questions.txt +++ b/week2/homework/questions.txt @@ -3,11 +3,19 @@ Containers, Blocks, and Iterators Sharing Functionality: Inheritance, Modules, and Mixins 1. What is the difference between a Hash and an Array? +Both are indexed collections of object references, but Arrays are indexed with integers, whereas Hashes are indexed with objects of any type (symbols, strings, etc.). Also Arrays are ordered collections, whereas Hashes are not necessarily ordered. 2. When would you use an Array over a Hash and vice versa? +I would use an Array over a Hash if I need to have an ordered collection, and I would use a Hash over an array if I need to map information to words or other objects. 3. What is a module? Enumerable is a built in Ruby module, what is it? +Modules are a way of grouping together methods, classes, and constants. +Enumerable is a standard mixin, implementing a bunch of methods (to iterate, map, search, etc.) in terms of the host class's each method. 4. Can you inherit more than one thing in Ruby? How could you get around this problem? +No, Ruby is a single-inheritance language. But we could get around this problem by using mixins, since Ruby classes can include the functionality of any number of mixins. 5. What is the difference between a Module and a Class? +A Module provides methods that can be used across multiple Classes. It cannot generate objects or inherit from a parent like Classes do. It can be mixed into other Modules or Classes whereas a Class cannot. + + diff --git a/week2/homework/simon_says.rb b/week2/homework/simon_says.rb new file mode 100644 index 0000000..6c9eec5 --- /dev/null +++ b/week2/homework/simon_says.rb @@ -0,0 +1,23 @@ +module SimonSays + + def echo(input) + input + end + + def shout(input) + input.upcase + end + + def repeat(input, number=2) + ([input] * number).join ' ' + end + + def start_of_word(input, number) + input[0...number] + end + + def first_word(input) + input.split(" ")[0] + end + +end diff --git a/week3/homework/calculator.rb b/week3/homework/calculator.rb new file mode 100644 index 0000000..88f076a --- /dev/null +++ b/week3/homework/calculator.rb @@ -0,0 +1,28 @@ +class Calculator + + def sum(input=0) + input.inject(0) {|sum, i| sum + i} + end + + def multiply(input1=0,input2=0 ) + + if !input1.kind_of?(Array) + input1 * input2 + else + input1.inject(1) {|sum, i| sum * i} + end + end + + def pow(input1=0, input2=0) + input1**input2 + end + + def fac(input=0) + if input == 0 + 1 + else + input * fac(input-1) + end + end + +end diff --git a/week3/homework/questions.txt b/week3/homework/questions.txt index dfb158d..a49b082 100644 --- a/week3/homework/questions.txt +++ b/week3/homework/questions.txt @@ -5,11 +5,19 @@ Please Read: - Chapter 22 The Ruby Language: basic types (symbols), variables and constants 1. What is a symbol? +A symbol is an object used to represent names and strings in the Ruby interpreter. 2. What is the difference between a symbol and a string? +Unlike strings, symbols are immutable. 3. What is a block and how do I call a block? +A block is a chunk of code that can be associated with method invocations. +I call a block using curly brackets ({}) or by writing between "do" and "end". 4. How do I pass a block to a method? What is the method signature? +You can pass a block to a method using the "yield" statement in the method definition, and with the block appended to the method call. +The method signature is its name and the names and default values of its arguments. 5. Where would you use regular expressions? +I would use regular expressions for processing text or search patterns for instance. + diff --git a/week4/homework/questions.txt b/week4/homework/questions.txt index bc1ab7c..1eac29f 100644 --- a/week4/homework/questions.txt +++ b/week4/homework/questions.txt @@ -3,7 +3,20 @@ Chapter 10 Basic Input and Output The Rake Gem: http://rake.rubyforge.org/ 1. How does Ruby read files? +Ruby can read files via the file.gets method used with a loop, or with iterators such as IO#each_line or IO.foreach. + 2. How would you output "Hello World!" to a file called my_output.txt? +I would use the following code: +File.open("output.txt", "w") do |file| + file.puts "Hello World!" +end + 3. What is the Directory class and what is it used for? +The Dir class creates directory streams representing directories in the underlying file system. It is used to create, query, filter or remove directories. + 4. What is an IO object? +An IO object is a bidirectional channel between a Ruby program and some external resource. + 5. What is rake and what is it used for? What is a rake task? +Rake is a make-like build tool written in Ruby. It is used for job automation: to specify tasks, describe dependencies and group tasks in a namespace. A rake task can be one of the built-in types or a block of my own Ruby code. + diff --git a/week4/homework/worker.rb b/week4/homework/worker.rb new file mode 100644 index 0000000..6c41d28 --- /dev/null +++ b/week4/homework/worker.rb @@ -0,0 +1,6 @@ +class Worker + def self.work(input = 1) + (input-1).times {yield} + yield + end +end diff --git a/week4/homework/worker_spec.rb b/week4/homework/worker_spec.rb new file mode 100644 index 0000000..dfc6f02 --- /dev/null +++ b/week4/homework/worker_spec.rb @@ -0,0 +1,36 @@ +require "#{File.dirname(__FILE__)}/worker" + +describe Worker do + + it "executes a block and returns a string" do + result = Worker.work do + "hello" + end + result.should == "hello" + end + + it "executes a block and returns a number" do + result = Worker.work do + 3 + 4 + end + result.should == 7 + end + + it "executes a block in the context of the calling method" do + n = 1 + result = Worker.work do + n + 4 + end + result.should == 5 + end + + + it "executes a block 3 times and returns the result" do + n = 5 + result = Worker.work(3) do + n += 1 + end + result.should == 8 + end + +end diff --git a/week7/homework/features/step_definitions/tic-tac-toe.rb b/week7/homework/features/step_definitions/tic-tac-toe.rb new file mode 100644 index 0000000..013f933 --- /dev/null +++ b/week7/homework/features/step_definitions/tic-tac-toe.rb @@ -0,0 +1,108 @@ +class TicTacToe + attr_accessor :player,:current_player,:board + + def initialize + @player = "" + @SYMBOLS = ["X", "O"] + @player_symbol = "" + @computer_symbol = "" + @over = false + @current_player = "" + @board = { + :A1 => " ", :A2 => " ", :A3 => " ", + :B1 => " ", :B2 => " ", :B3 => " ", + :C1 => " ", :C2 => " ", :C3 => " " + } + @open_spots = [:A1,:A2,:A3,:B1,:B2,:B3,:C1,:C2,:C3] + @player_won = false + @computer_won = false + @draw = false + end + + def welcome_player + welcome = "Welcome "+ @player + players = ["Computer", @player] + @current_player = players.sample + @SYMBOLS.shuffle + @player_symbol = @SYMBOLS[0] + @computer_symbol = @SYMBOLS[1] + welcome + end + + def computer_move + puts "Computer moves" + cMove = @open_spots.sample + @board[cMove]=@computer_symbol + @open_spots.delete(cMove) + @current_player=@player + end + + def indicate_player_turn + puts @player + "'s Move:" + end + + def player_move + pMove = gets.chomp + valid = false + until valid == true + if @board.keys.include?(pMove.to_sym)==false + puts "Invalid input!" + pMove = gets.chomp + elsif @open_spots.include?(pMove.to_sym)==false + puts "Spot already taken!" + pMove = gets.chomp + else + valid = true + end + end + @board[pMove.to_sym]=@player_symbol + @open_spots.delete(pMove.to_sym) + @current_player="Computer" + end + + def current_state + current_state = " 1 2 3\n -----\n "+"A|#{@board[:A1]} "+"#{@board[:A2]} "+"#{@board[:A3]}|"+"\n "+"B|#{@board[:B1]} "+"#{@board[:B2]} "+"#{@board[:B3]}|"+"\n "+"C|#{@board[:C1]} "+"#{@board[:C2]} "+"#{@board[:C3]}|"+"\n -----" + end + + def over? + #detect 3 consecutives symbols + if (@board[:A1]==@board[:A2] && @board[:A1]==@board[:A3] && @board[:A1]=="X" ) || (@board[:B1]==@board[:B2] && @board[:B1]==@board[:B3] && @board[:B1]=="X" ) || (@board[:C1]==@board[:C2] && @board[:C1]==@board[:C3] && @board[:C1]=="X" ) || (@board[:A1]==@board[:B1] && @board[:A1]==@board[:C1] && @board[:A1]=="X" ) || (@board[:A2]==@board[:B2] && @board[:A2]==@board[:C2] && @board[:A2]=="X" ) || (@board[:A3]==@board[:B3] && @board[:A3]==@board[:C3] && @board[:A3]=="X" ) || (@board[:A1]==@board[:B2] && @board[:A1]==@board[:C3] && @board[:A1]=="X" ) || (@board[:A3]==@board[:B2] && @board[:A3]==@board[:C1] && @board[:A3]=="X" ) + if @player_symbol == "X" + @player_won = true + elsif @computer_symbol == "X" + @computer_won = true + end + @over = true + elsif (@board[:A1]==@board[:A2] && @board[:A1]==@board[:A3] && @board[:A1]=="O" ) || (@board[:B1]==@board[:B2] && @board[:B1]==@board[:B3] && @board[:B1]=="O" ) || (@board[:C1]==@board[:C2] && @board[:C1]==@board[:C3] && @board[:C1]=="O" ) || (@board[:A1]==@board[:B1] && @board[:A1]==@board[:C1] && @board[:A1]=="O" ) || (@board[:A2]==@board[:B2] && @board[:A2]==@board[:C2] && @board[:A2]=="O" ) || (@board[:A3]==@board[:B3] && @board[:A3]==@board[:C3] && @board[:A3]=="O" ) || (@board[:A1]==@board[:B2] && @board[:A1]==@board[:C3] && @board[:A1]=="O" ) || + (@board[:A3]==@board[:B2] && @board[:A3]==@board[:C1] && @board[:A3]=="O" ) + if @player_symbol == "O" + @player_won = true + elsif @computer_symbol == "O" + @computer_won = true + end + @over = true + elsif @open_spots.empty? + @draw = true + @over = true + end + @over + end + + def player_won? + @player_won + end + + def computer_won? + @computer_won + end + + def draw? + @draw + end + + def determine_winner + + end + +end + diff --git a/week7/homework/play_game.rb b/week7/homework/play_game.rb index 0535830..7b99f10 100644 --- a/week7/homework/play_game.rb +++ b/week7/homework/play_game.rb @@ -10,7 +10,7 @@ when "Computer" @game.computer_move when @game.player - @game.indicate_palyer_turn + @game.indicate_player_turn @game.player_move end puts @game.current_state diff --git a/week7/homework/questions.txt b/week7/homework/questions.txt index d55387d..f35323a 100644 --- a/week7/homework/questions.txt +++ b/week7/homework/questions.txt @@ -3,7 +3,22 @@ Please Read Chapters 23 and 24 DuckTyping and MetaProgramming Questions: 1. What is method_missing and how can it be used? +When sending a message to an object if the object has no method corresponding to the message a NoMethodError exception is created. This exception can be avoided though by adding a method called method_missing to the object. This method allows to handle nicely unaswerable messages. It can be used by defining method_missing in the object's class, and we can pass the name of the wrongly called method, the array of arguments and the block that was originally passed (if any). + def method_missing(method, *args, &block) + #add here desired behavior in case of non-existing method + end + 2. What is and Eigenclass and what is it used for? Where Do Singleton methods live? +An Eigenclass is an anonymous class created dynamically by Ruby when methods are created for a specific object and not shared by other instances of this object's class. +Such methods are called Singleton methods and live in the Eigenclass. + 3. When would you use DuckTypeing? How would you use it to improve your code? +I would use Ducktyping to keep my code concise (DRY). + 4. What is the difference between a class method and an instance method? What is the difference between instance_eval and class_eval? +A class method is a method that is called on a class and an instance method is a method that is called on an instance of a class. Class_eval and instance_eval differ in the way they set up the environment for method definition. Class_eval sets the environment as if in the body of a class definition, so method definitions will define instance methods. On the contrary calling instance_eval on a class acts as if working inside the singleton class of self. Any methods defined will become class methods. + 5. What is the difference between a singleton class and a singleton method? +A singleton class is a class which defines a single object. +A singleton method is a method that belongs to a single object rather than to a whole class and other objects. +