Permalink
Browse files

rename chX to sessionX

  • Loading branch information...
1 parent 2709901 commit eadc31ec3077172462587401875ebd61031ee2d1 @JoshCheek committed Jun 11, 2011
Showing with 137 additions and 96 deletions.
  1. +36 −36 Rakefile
  2. +0 −6 ch5/examples/5_calculator/calculator.rb
  3. 0 {ch1 → session1}/challenge/1_arithmetic.rb
  4. 0 {ch1 → session1}/challenge/2_arithmetic.rb
  5. 0 {ch1 → session1}/challenge/3_simple_logic.rb
  6. 0 {ch1 → session1}/challenge/4_logic.rb
  7. 0 {ch1 → session1}/challenge/5_string.rb
  8. 0 {ch1 → session1}/challenge/6_string.rb
  9. 0 {ch1 → session1}/challenge/7_string.rb
  10. 0 {ch1 → session1}/examples/1_first_program.rb
  11. 0 {ch1 → session1}/examples/2_check_odd.rb
  12. 0 {ch1 → session1}/examples/3_rememberer.rb
  13. 0 {ch1 → session1}/examples/4_rememberer2.rb
  14. 0 {ch1 → session1}/notes/01-intro.rb
  15. 0 {ch1 → session1}/notes/02-conventions.rb
  16. 0 {ch1 → session1}/notes/03-object-definition.rb
  17. 0 {ch1 → session1}/notes/04-variables.rb
  18. 0 {ch1 → session1}/notes/05-methods.rb
  19. 0 {ch1 → session1}/notes/06-method-scope.rb
  20. 0 {ch1 → session1}/notes/07-method-arguments.rb
  21. 0 {ch1 → session1}/notes/08-operators.rb
  22. 0 {ch1 → session1}/notes/09-numbers.rb
  23. 0 {ch1 → session1}/notes/10-introducing-strings.rb
  24. 0 {ch1 → session1}/notes/11-stdin-and-stdout.rb
  25. 0 {ch1 → session1}/notes/12-puts.rb
  26. 0 {ch1 → session1}/notes/13-single-vs-double-quotes.rb
  27. 0 {ch1 → session1}/notes/14-operators-on-strings.rb
  28. 0 {ch1 → session1}/notes/15-interpolation.rb
  29. 0 {ch1 → session1}/notes/16-p.rb
  30. 0 {ch1 → session1}/notes/17-naming-conventions.rb
  31. 0 {ch1 → session1}/notes/18-keywords.rb
  32. 0 {ch1 → session1}/notes/19-nil.rb
  33. 0 {ch1 → session1}/notes/20-logic.rb
  34. 0 {ch1 → session1}/notes/21-true-and-false.rb
  35. 0 {ch1 → session1}/notes/22-if-else.rb
  36. 0 {ch1 → session1}/notes/23-if-returns-a-value.rb
  37. 0 {ch1 → session1}/notes/24-go-do-the-challenges.rb
  38. 0 {ch1 → session1}/solved/1.rb
  39. 0 {ch1 → session1}/solved/2.rb
  40. 0 {ch1 → session1}/solved/3.rb
  41. 0 {ch1 → session1}/solved/4.rb
  42. 0 {ch1 → session1}/solved/5.rb
  43. 0 {ch1 → session1}/solved/6.rb
  44. 0 {ch1 → session1}/solved/7.rb
  45. 0 {ch1 → session1}/spec/1.rb
  46. 0 {ch1 → session1}/spec/2.rb
  47. 0 {ch1 → session1}/spec/3.rb
  48. 0 {ch1 → session1}/spec/4.rb
  49. 0 {ch1 → session1}/spec/5.rb
  50. 0 {ch1 → session1}/spec/6.rb
  51. 0 {ch1 → session1}/spec/7.rb
  52. 0 {ch2 → session2}/challenge/10_classes.rb
  53. 0 {ch2 → session2}/challenge/11_classes.rb
  54. 0 {ch2 → session2}/challenge/12_classes.rb
  55. 0 {ch2 → session2}/challenge/13_classes_iterating_sorting.rb
  56. 0 {ch2 → session2}/challenge/1_input_output.rb
  57. 0 {ch2 → session2}/challenge/2_input_output_control.rb
  58. 0 {ch2 → session2}/challenge/3_array.rb
  59. 0 {ch2 → session2}/challenge/4_array.rb
  60. 0 {ch2 → session2}/challenge/5_array.rb
  61. 0 {ch2 → session2}/challenge/6_array.rb
  62. 0 {ch2 → session2}/challenge/7_array.rb
  63. 0 {ch2 → session2}/challenge/8_array.rb
  64. 0 {ch2 → session2}/challenge/9_input_output_logic_string.rb
  65. 0 {ch2 → session2}/examples/1_output.rb
  66. 0 {ch2 → session2}/examples/2_gets.rb
  67. 0 {ch2 → session2}/examples/3_array.rb
  68. 0 {ch2 → session2}/examples/4_classes.rb
  69. 0 {ch2 → session2}/notes/01-a-quick-word-about-blocks.rb
  70. 0 {ch2 → session2}/notes/02-arrays.rb
  71. 0 {ch2 → session2}/notes/03-array-iterating.rb
  72. 0 {ch2 → session2}/notes/04-array-filtering.rb
  73. 0 {ch2 → session2}/notes/05-other-useful-array-methods.rb
  74. 0 {ch2 → session2}/notes/06-classes.rb
  75. 0 {ch2 → session2}/notes/07-class-examples.rb
  76. 0 {ch2 → session2}/notes/08-methods-go-in-classes.rb
  77. 0 {ch2 → session2}/notes/09-class-questions.rb
  78. 0 {ch2 → session2}/notes/10-instance-variables.rb
  79. 0 {ch2 → session2}/notes/11-naming-methods.rb
  80. 0 {ch2 → session2}/notes/12-attr_accessor.rb
  81. 0 {ch2 → session2}/notes/13-initializing.rb
  82. 0 {ch2 → session2}/notes/14-self.rb
  83. 0 {ch2 → session2}/notes/15-more-on-method-scope.rb
  84. 0 {ch2 → session2}/notes/16-THIS-IS-GONNA-TRIP-YOU-UP.rb
  85. 0 {ch2 → session2}/notes/17-singleton-classes.rb
  86. 0 {ch2 → session2}/notes/18-class-instance-variables.rb
  87. 0 {ch2 → session2}/notes/19-last-words.rb
  88. 0 {ch2 → session2}/solved/1.rb
  89. 0 {ch2 → session2}/solved/10.rb
  90. 0 {ch2 → session2}/solved/11.rb
  91. 0 {ch2 → session2}/solved/12.rb
  92. 0 {ch2 → session2}/solved/13.rb
  93. 0 {ch2 → session2}/solved/2.rb
  94. 0 {ch2 → session2}/solved/3.rb
  95. 0 {ch2 → session2}/solved/4.rb
  96. 0 {ch2 → session2}/solved/5.rb
  97. 0 {ch2 → session2}/solved/6.rb
  98. 0 {ch2 → session2}/solved/7.rb
  99. 0 {ch2 → session2}/solved/8.rb
  100. 0 {ch2 → session2}/solved/9.rb
  101. 0 {ch2 → session2}/spec/1.rb
  102. 0 {ch2 → session2}/spec/10.rb
  103. 0 {ch2 → session2}/spec/11.rb
  104. 0 {ch2 → session2}/spec/12.rb
  105. 0 {ch2 → session2}/spec/13.rb
  106. 0 {ch2 → session2}/spec/2.rb
  107. 0 {ch2 → session2}/spec/3.rb
  108. 0 {ch2 → session2}/spec/4.rb
  109. 0 {ch2 → session2}/spec/5.rb
  110. 0 {ch2 → session2}/spec/6.rb
  111. 0 {ch2 → session2}/spec/7.rb
  112. 0 {ch2 → session2}/spec/8.rb
  113. 0 {ch2 → session2}/spec/9.rb
  114. 0 {ch2 → session2}/spec/helper.rb
  115. 0 {ch3 → session3}/challenge/10_hashes.rb
  116. 0 {ch3 → session3}/challenge/11_blocks_or_procs.rb
  117. 0 {ch3 → session3}/challenge/12_blocks.rb
  118. 0 {ch3 → session3}/challenge/13_proc.rb
  119. 0 {ch3 → session3}/challenge/14_var_args_and_hash.rb
  120. 0 {ch3 → session3}/challenge/15_hash.rb
  121. 0 {ch3 → session3}/challenge/16_hash.rb
  122. 0 {ch3 → session3}/challenge/17_hashes.rb
  123. 0 {ch3 → session3}/challenge/1_blocks.rb
  124. 0 {ch3 → session3}/challenge/2_hashes.rb
  125. 0 {ch3 → session3}/challenge/3_hashes.rb
  126. 0 {ch3 → session3}/challenge/4_hashes.rb
  127. 0 {ch3 → session3}/challenge/5_blocks.rb
  128. 0 {ch3 → session3}/challenge/6_arguments.rb
  129. 0 {ch3 → session3}/challenge/7_hashes.rb
  130. 0 {ch3 → session3}/challenge/8_blocks.rb
  131. 0 {ch3 → session3}/challenge/9_hashes.rb
  132. 0 {ch3 → session3}/examples/1_hashes.rb
  133. 0 {ch3 → session3}/examples/2_blocks.rb
  134. 0 {ch3 → session3}/examples/3_stack.rb
  135. 0 {ch3 → session3}/notes/01-symbols-introduction.rb
  136. 0 {ch3 → session3}/notes/02-symbols-always-the-same.rb
  137. 0 {ch3 → session3}/notes/03-hash-introduction.rb
  138. 0 {ch3 → session3}/notes/04-hash-literals.rb
  139. 0 {ch3 → session3}/notes/05-hash-setting-and-getting.rb
  140. 0 {ch3 → session3}/notes/06-hash-keys.rb
  141. 0 {ch3 → session3}/notes/07-hash-iterating.rb
  142. 0 {ch3 → session3}/notes/08-proc-introduction.rb
  143. 0 {ch3 → session3}/notes/09-procs-can-see-their-environment.rb
  144. 0 {ch3 → session3}/notes/10-blocks-introduction.rb
  145. 0 {ch3 → session3}/notes/11-block-params-and-return.rb
  146. 0 {ch3 → session3}/notes/12-all-methods-take-blocks.rb
  147. 0 {ch3 → session3}/notes/13-difference-between-block-syntaxes.rb
  148. 0 {ch3 → session3}/notes/14-storing-blocks-for-later.rb
  149. 0 {ch3 → session3}/notes/15-forwarding-blocks.rb
  150. 0 {ch3 → session3}/notes/16-optional-params.rb
  151. 0 {ch3 → session3}/notes/17-variable-lengthed-params.rb
  152. 0 {ch3 → session3}/notes/18-hash-params.rb
  153. 0 {ch3 → session3}/notes/19-putting-it-all-together.rb
  154. 0 {ch3 → session3}/notes/20-last-words.rb
  155. 0 {ch3 → session3}/solved/1.rb
  156. 0 {ch3 → session3}/solved/10.rb
  157. 0 {ch3 → session3}/solved/11.rb
  158. 0 {ch3 → session3}/solved/12.rb
  159. 0 {ch3 → session3}/solved/13.rb
  160. 0 {ch3 → session3}/solved/14.rb
  161. 0 {ch3 → session3}/solved/15.rb
  162. 0 {ch3 → session3}/solved/16.rb
  163. 0 {ch3 → session3}/solved/17.rb
  164. 0 {ch3 → session3}/solved/2.rb
  165. 0 {ch3 → session3}/solved/3.rb
  166. 0 {ch3 → session3}/solved/4.rb
  167. 0 {ch3 → session3}/solved/5.rb
  168. 0 {ch3 → session3}/solved/6.rb
  169. 0 {ch3 → session3}/solved/7.rb
  170. 0 {ch3 → session3}/solved/8.rb
  171. 0 {ch3 → session3}/solved/9.rb
  172. 0 {ch3 → session3}/spec/1.rb
  173. 0 {ch3 → session3}/spec/10.rb
  174. 0 {ch3 → session3}/spec/11.rb
  175. 0 {ch3 → session3}/spec/12.rb
  176. 0 {ch3 → session3}/spec/13.rb
  177. 0 {ch3 → session3}/spec/14.rb
  178. 0 {ch3 → session3}/spec/15.rb
  179. 0 {ch3 → session3}/spec/16.rb
  180. 0 {ch3 → session3}/spec/17.rb
  181. 0 {ch3 → session3}/spec/2.rb
  182. 0 {ch3 → session3}/spec/3.rb
  183. 0 {ch3 → session3}/spec/4.rb
  184. 0 {ch3 → session3}/spec/5.rb
  185. 0 {ch3 → session3}/spec/6.rb
  186. 0 {ch3 → session3}/spec/7.rb
  187. 0 {ch3 → session3}/spec/8.rb
  188. 0 {ch3 → session3}/spec/9.rb
  189. 0 {ch3 → session3}/spec/helper.rb
  190. 0 {ch4 → session4}/challenge/1_stack_classes_inspect.rb
  191. 0 {ch4 → session4}/challenge/2_subclassing_require.rb
  192. 0 {ch4 → session4}/challenge/3_inject_blocks_enumerable.rb
  193. 0 {ch4 → session4}/challenge/4_||.rb
  194. 0 {ch4 → session4}/challenge/5_file.rb
  195. 0 {ch4 → session4}/challenge/6_singleton_class_string.rb
  196. 0 {ch4 → session4}/challenge/7_introspection.rb
  197. 0 {ch4 → session4}/challenge/8_exceptions.rb
  198. 0 {ch4 → session4}/challenge/9_exceptions.rb
  199. 0 {ch4 → session4}/notes/01-&&-return-values.rb
  200. 0 {ch4 → session4}/notes/02-||-return-values.rb
  201. 0 {ch4 → session4}/notes/03-||=.rb
  202. 0 {ch4 → session4}/notes/04-introspection.rb
  203. 0 {ch4 → session4}/notes/05-ranges.rb
  204. 0 {ch4 → session4}/notes/06-files.rb
  205. 0 {ch4 → session4}/notes/07-working-dir-vs-file-dir.rb
  206. 0 {ch4 → session4}/notes/08.a-require.rb
  207. 0 {ch4 → session4}/notes/08.b-require.rb
  208. 0 {ch4 → session4}/notes/09-inheritance-introduction.rb
  209. 0 {ch4 → session4}/notes/10-subclasses-inherit-methods.rb
  210. 0 {ch4 → session4}/notes/11-overriding-inherited-methods.rb
  211. 0 {ch4 → session4}/notes/12-super-to-invoke-inherited.rb
  212. 0 {ch4 → session4}/notes/13-inheritance-example.rb
  213. 0 {ch4 → session4}/notes/14-ancestors.rb
  214. 0 {ch4 → session4}/notes/15-exceptions-introduction.rb
  215. 0 {ch4 → session4}/notes/16-exceptions-rescuing.rb
  216. 0 {ch4 → session4}/notes/17-raising-your-own.rb
  217. 0 {ch4 → session4}/resources/8.1.template
  218. 0 {ch4 → session4}/resources/8.2.template
  219. 0 {ch4 → session4}/resources/8.3.template
  220. 0 {ch4 → session4}/resources/8.4.template
  221. 0 {ch4 → session4}/resources/8.5.template
  222. 0 {ch4 → session4}/resources/8.6.template
  223. 0 {ch4 → session4}/resources/8.7.template
  224. 0 {ch4 → session4}/resources/8.8.template
  225. 0 {ch4 → session4}/resources/8.9.template
  226. 0 {ch4 → session4}/solved/1.rb
  227. 0 {ch4 → session4}/solved/2.rb
  228. 0 {ch4 → session4}/solved/3.rb
  229. 0 {ch4 → session4}/solved/4.rb
  230. 0 {ch4 → session4}/solved/5.rb
  231. 0 {ch4 → session4}/solved/6.rb
  232. 0 {ch4 → session4}/solved/7.rb
  233. 0 {ch4 → session4}/solved/8.rb
  234. 0 {ch4 → session4}/solved/9.rb
  235. 0 {ch4 → session4}/spec/1.rb
  236. 0 {ch4 → session4}/spec/2.rb
  237. 0 {ch4 → session4}/spec/3.rb
  238. 0 {ch4 → session4}/spec/4.rb
  239. 0 {ch4 → session4}/spec/5.rb
  240. 0 {ch4 → session4}/spec/6.rb
  241. 0 {ch4 → session4}/spec/7.rb
  242. 0 {ch4 → session4}/spec/8.rb
  243. 0 {ch4 → session4}/spec/9.rb
  244. 0 {ch5 → session5}/challenge/1_singleton_class_string_exception.rb
  245. 0 {ch5 → session5}/challenge/2_blocks_var_args.rb
  246. 0 {ch5 → session5}/challenge/5_modules.rb
  247. 0 {ch5 → session5}/challenge/6_exceptions_regex_reflection.rb
  248. 0 {ch5 → session5}/challenge/7_sinatra.rb
  249. 0 {ch5 → session5}/examples/1_load_me.rb
  250. 0 {ch5 → session5}/examples/2_regex.rb
  251. 0 {ch5 → session5}/examples/3_sinatra_hello_world.rb
  252. 0 {ch5 → session5}/examples/4_sinatra_params.rb
  253. +1 −0 session5/examples/5_calculator
  254. 0 {ch5 → session5}/examples/blog/.gems
  255. 0 {ch5 → session5}/examples/blog/config.ru
  256. 0 {ch5 → session5}/examples/blog/controllers.rb
  257. BIN {ch5 → session5}/examples/blog/development.sqlite3
  258. 0 {ch5 → session5}/examples/blog/helpers.rb
  259. 0 {ch5 → session5}/examples/blog/models.rb
  260. 0 {ch5 → session5}/examples/blog/public/css/main.css
  261. 0 {ch5 → session5}/examples/blog/readme.markup
  262. 0 {ch5 → session5}/examples/blog/signup.rb
  263. 0 {ch5 → session5}/examples/blog/views/index.erb
  264. 0 {ch5 → session5}/examples/blog/views/layout.erb
  265. 0 {ch5 → session5}/examples/blog/views/new.erb
  266. 0 {ch5 → session5}/examples/blog/views/show.erb
  267. +100 −54 {ch5 → session5}/notes/notes.rb
  268. 0 {ch5 → session5}/solved/1.rb
  269. 0 {ch5 → session5}/solved/2.rb
  270. 0 {ch5 → session5}/solved/5.rb
  271. 0 {ch5 → session5}/solved/6.rb
  272. 0 {ch5 → session5}/solved/7.rb
  273. 0 {ch5 → session5}/spec/1.rb
  274. 0 {ch5 → session5}/spec/2.rb
  275. 0 {ch5 → session5}/spec/5.rb
  276. 0 {ch5 → session5}/spec/6.rb
  277. 0 {ch5 → session5}/spec/7.rb
View
@@ -4,19 +4,19 @@ module Rake
def display_tasks_and_comments
displayable_tasks = tasks.select { |t| t.comment && t.name =~ options.show_task_pattern }.sort do
|t1,t2|
- one_is_ch = t1.name[/^\d+:(\d+|all)$/]
- two_is_ch = t2.name[/^\d+:(\d+|all)$/]
- if one_is_ch && two_is_ch
- ch1 , prb1 = t1.name.split ':'
- ch2 , prb2 = t2.name.split ':'
- if ch1 == ch2
+ one_is_session = t1.name[/^\d+:(\d+|all)$/]
+ two_is_session = t2.name[/^\d+:(\d+|all)$/]
+ if one_is_session && two_is_session
+ session1 , prb1 = t1.name.split ':'
+ session2 , prb2 = t2.name.split ':'
+ if session1 == session2
if prb1 == 'all' then 1 elsif prb2 == 'all' then -1 else prb1.to_i <=> prb2.to_i end
else
- ch1.to_i <=> ch2.to_i
+ session1.to_i <=> session2.to_i
end
- elsif one_is_ch
+ elsif one_is_session
-1
- elsif two_is_ch
+ elsif two_is_session
1
else
t1.name <=> t2.name
@@ -56,54 +56,54 @@ end
# runs the spec against the challenge
# if the environment variable 'solved' has been set,
# then it runs them against the solved challenge instead
-def run_spec(chapter,problem)
- ch = "#{File.dirname(__FILE__)}/ch#{chapter}"
+def run_spec(session_num,problem)
+ sess = "#{File.dirname(__FILE__)}/session#{session_num}"
if ENV['solved']
- problem_dir = "#{ch}/solved/#{problem}.rb"
+ problem_dir = "#{sess}/solved/#{problem}.rb"
else
- problem_dir = Dir["#{ch}/challenge/#{problem}_*"].first
+ problem_dir = Dir["#{sess}/challenge/#{problem}_*"].first
end
- sh "ruby -c '#{problem_dir}'" # check syntax
- sh "rspec -cr '#{problem_dir}' -r enumerator '#{ch}/spec/#{problem}.rb' --fail-fast" # run spec (c for colour, r to require the files, enumerator required for 1.8.6 compatibility)
+ sh "ruby -c '#{problem_dir}'" # check syntax
+ sh "rspec -cr '#{problem_dir}' -r enumerator '#{sess}/spec/#{problem}.rb' --fail-fast" # run spec (c for colour, r to require the files, enumerator required for 1.8.6 compatibility)
end
-# returns array of chapters
-def get_chapters
- Dir['*'].grep(/^ch\d+$/).map { |folder_name| folder_name[/\d+$/] }
+# returns array of sessions
+def get_sessions
+ Dir['*'].grep(/^session\d+$/).map { |folder_name| folder_name[/\d+$/] }
end
-# returns hash where each key is the chapter to test
-# each value is a range indicating the problems available for this chapter
-def chapters_with_problems
- get_chapters.inject Hash.new do |chapters_with_sections,chapter|
- challenges = Dir["ch#{chapter}/challenge/*"]
- chapters_with_sections[chapter] = challenges.map { |challenge| challenge[%r([^/]+?$)].to_i }.sort
- chapters_with_sections
+# returns hash where each key is the session to test
+# each value is a range indicating the problems available for this session
+def sessions_with_problems
+ get_sessions.inject Hash.new do |sessions_with_sections, session|
+ challenges = Dir["session#{session}/challenge/*"]
+ sessions_with_sections[session] = challenges.map { |challenge| challenge[%r([^/]+?$)].to_i }.sort
+ sessions_with_sections
end
end
# create tasks for each challenge
-chapters_with_problems.each do |chapter,problems|
- namespace chapter do
+sessions_with_problems.each do |session, problems|
+ namespace session do
problems.each do |problem|
- desc "Test chapter#{chapter} problem#{problem}"
- task(problem) { run_spec chapter , problem }
+ desc "Test session#{session} problem#{problem}"
+ task(problem) { run_spec session , problem }
end
- desc "Test chapter#{chapter} all problems"
+ desc "Test session#{session} all problems"
task :all => problems.to_a
end
end
-task :default => get_chapters.map { |chapter| "#{chapter}:all" }
+task :default => get_sessions.map { |session| "#{session}:all" }
-desc 'create chapter skeleton'
-task :add_ch do
- ch = "ch#{ENV['ch']||get_chapters.size.next}"
- makedirs 'challenge' , 'examples' , 'notes' , 'solved' , 'spec' , :path => ch
- touch "#{ch}/notes/josh.rb"
+desc 'create session skeleton'
+task :add_sess do
+ sess = "session#{ENV['sess']||get_sessions.size.next}"
+ makedirs 'challenge' , 'examples' , 'notes' , 'solved' , 'spec' , :path => sess
+ touch "#{sess}/notes/josh.rb"
end
@@ -1,6 +0,0 @@
-# Lets create a simple calculator app together, it should have a get method for localhost:4567/calculator that displays two forms
-# the first form should post (note that post is one of those http methods) to localhost:4567/add, and have two fields named "num1" and "num2"
-# the second form should post to localhost:4567/add1 with the same args
-# the page that they go to should display the result, and have a button to get back to calculator
-
-
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Submodule 5_calculator added at 4d6916
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,68 +1,114 @@
-# ===== Exceptions =====
-# errors and exceptions are used to say "something fucked up"
-# it halts evaluation, and returns to where it was called from
-# incrementally making its way up the stack (the series of methods that were called to get to
-# wherever the exception was raised) until it is either rescued, or crashes the program
-
-# There are quite a few exceptions in Ruby (one of your challenges will be to find them :)
-# You've seen them before, but perhaps didn't know what they were
-def method_with_one_parameter(n) end
-begin
- method_with_one_parameter(1,2,3)
- 1 + 2 # =>
-rescue => e
- e # => #<ArgumentError: wrong number of arguments (3 for 1)>
- e.class # => ArgumentError
- e.class.ancestors # => [ArgumentError, StandardError, Exception, Object, Kernel]
-end
+# 01234567890123456789012345678901234567890123456789012345678901234567
-# You can rescue specific exceptions if you like
-begin
- method_with_one_parameter(1,2,3)
-rescue ZeroDivisionError => e
- e # =>
-rescue ArgumentError => e
- e # => #<ArgumentError: wrong number of arguments (3 for 1)>
+# ===== Modules =====
+# Generally, inheriting classes is becoming less embraced by the Ruby community
+# Now, people usually prefer to use modules instead of inheritence.
+# A class can only inherit from one other class, but it can include as many modules as it likes (this is commonly called a mix-in)
+#
+# Modules have the feel of a class in that they have methods on them. But they cannot be instantiated.
+# Instead, you declare that the methods in the module should extend an object, or be included in a class
+# and all the methods the module contains will be magically dropped into the class.
+module Threes
+
+ def threes_r0
+ self.select { |i| i % 3 == 0 }
+ end
+
+ def threes_r1
+ select { |i| i % 3 == 1 }
+ end
+
+ def threes_r2
+ select { |i| i % 3 == 2 }
+ end
+
end
-begin
- 1 / 0
-rescue ZeroDivisionError => e
- e # => #<ZeroDivisionError: divided by 0>
-rescue ArgumentError => e
- e # =>
-end
-# If you handle the exception, you may want to try again
-numerator = 100
-denominator = 0
-begin
- result = numerator / denominator
-rescue ZeroDivisionError => e
- denominator += 1
- retry
+# Extending an object with a module
+sequence = 0...30
+sequence.extend Threes
+
+
+# if we look in sequence's singleton class, we see that Threes is now an ancestor of it
+# but this has only affected our one object
+(class << sequence; self; end).ancestors # =>
+(class << Range.new(0,0); self; end).ancestors # =>
+
+sequence.threes_r0 # =>
+sequence.threes_r1 # =>
+sequence.threes_r2 # =>
+
+sequence # =>
+0...30 # =>
+sequence.methods.grep(/threes/) # =>
+(0...30).methods.grep(/threes/) # =>
+
+# Questions: Where did the select come from in threes_rn?
+# Can you think of another object we could extend with this module?
+
+
+# Including a module in a class' instance methods
+# A class has lots of instance methods that its instances are able to use
+# You can include the module's methods in them as well
+Range.ancestors # =>
+class Range
+ include Threes
end
-result # => 100
-denominator # => 1
-
-# You can raise your own exceptions
-def show_exception
- begin
- yield
- rescue Exception => e
- e
+Range.ancestors # =>
+
+sequence # =>
+0...30 # =>
+sequence.methods.grep(/threes/) # =>
+(0...30).methods.grep(/threes/) # =>
+
+
+
+# Modules are also commonly used for namespacing
+# maybe you want to try the same problem several days in a row, to see how your approach changes
+module Day1Solutions
+ class MinFinder
+ def initialize(a,b)
+ @a , @b = a , b
+ end
+ def solve
+ if @a < @b then @a else @b end
+ end
end
end
-def get_names(full_name)
- raise ArgumentError.new("you need to submit the name as 'Firstname Lastname'") unless full_name[ /^[A-Z][a-z]* [A-Z][a-z]*$/ ]
- full_name.split
+module Day2Solutions
+ class MinFinder
+ def initialize(a,b)
+ @elements = [ a , b ]
+ end
+ def solve
+ @elements.min
+ end
+ end
end
-show_exception { get_names 'josh cheek' } # => #<ArgumentError: you need to submit the name as 'Firstname Lastname'>
-show_exception { get_names 'Josh Cheek' } # => ["Josh", "Cheek"]
+day1 = Day1Solutions::MinFinder.new 10 , 5
+day2 = Day2Solutions::MinFinder.new 10 , 5
+day1 # =>
+day2 # =>
+day1.solve # =>
+day2.solve # =>
+
+# that is a lot to type, though, I think I like Day2Solutions better, it's easier to read
+# that is the one I want to use from now on, but I don't want to have to keep typing Day2Solutions::MinFinder.new
+# we can include day2 solutions into our main
+include Day2Solutions
+MinFinder.new 10 , 5 # =>
+
+# This is a common way to get nicer functionality
+# For example, the FileUtils module (http://ruby-doc.org/core/classes/FileUtils.html), which is in the Ruby standard library
+# is included when working with rake files, this lets you say things like "cd 'ch4'" instead of "FileUtils.cd 'ch4'"
+
+# ~> -:264:in `lkjlkj': super: no superclass method `lkjlkj' for #<Engineer:0x0000010090ba40 @hours_worked=10> (NoMethodError)
+# ~> from -:268:in `<main>'
+
-# QUESTION: Why did our program return an ArgumentError? We caught an Exception
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit eadc31e

Please sign in to comment.