Permalink
Browse files

Work in progress for lessons

  • Loading branch information...
tamersalama committed Nov 24, 2011
1 parent 33ba4be commit 1271d57b11bf11e399d4a582addd67896a691af8
Showing with 135 additions and 49 deletions.
  1. +5 −3 lessons/01.yaml
  2. +4 −1 lessons/02.yaml
  3. +65 −41 lessons/03.yaml
  4. +4 −4 lessons/04.yaml
  5. +57 −0 ref_lessons/03.yaml
View
@@ -31,9 +31,11 @@ content: |
### Schedule
- * 1-ish hour of ruby
- * 4-ish hours of rails, broken up in 1-ish hour steps
-
+ * ~1 hour Installation
+ * ~2 hours Ruby
+ * ~4 hours Rails
+ * ~2 hours Q/A
+
This is just a rough guideline, not a mandate. Some steps you'll go
over and some you'll go under. It'll all work out by the end of the
day... unless we really screwed something up. :D
View
@@ -11,6 +11,7 @@ goal: |
* use and understand collections
* use loops
+
steps: |
Open up a terminal window and try the following:
@@ -36,10 +37,12 @@ steps: |
puts f
end
- if my_variable > 1 then
+ if my_variable > 1
puts "YAY!"
end
+
+
explanation: |
* irb
View
@@ -1,67 +1,91 @@
---
-content: |
- ## Other Tools to help you learn Ruby
+section_title: Introduction to Ruby
+goal_title: Slightly Advanced Ruby
+goal: |
+
+ By the end of this section you will:
+
+ * create hashes (name/value stores)
+ * loop against a hash
+ * create a Class & method
+ * call a method
+ * Open-up a core class & define new methods
+
+
+steps: |
+
+ Open up a terminal window and try the following:
- ### ri
+ $ irb
- ri is a tool to look up ruby documentation:
+ some_hash = {1 => "Calgary", 2 => "Edmonton"}
- $ ri String.split
- = String.split
+ some_hash.keys
- (from ruby core)
- ------------------------------------------------------------------------------
- str.split(pattern=$;, [limit]) => anArray
+ some_hash.values
- ------------------------------------------------------------------------------
+ some_hash.each do |k, v|
+ puts "Key is #{k}, Value is #{v}"
+ end
- Divides str into substrings based on a delimiter, returning an array of
- these substrings.
- ...
+ class Workshop
+ def size
+ 35
+ end
+ end
- You can do a lot with it:
+ w = Workshop.new
- * `ri Class` -- looks up the class documentation and shows all the methods available.
- * `ri Class.method` -- looks up a specific method on a class or module.
- * `ri method` -- searches all classes for matching methods
+ w.size
- If running ri doesn't work and you've installed ruby using rvm, try
- running this command first:
+ a = "My Name"
- $ rvm docs generate
+ a.class
- ### irb
+ a.is_a?(Array)
- We've already introduced irb above, but it can't be stressed enough
- that having an interactive live session with ruby is invaluable. You
- can learn a lot from it.
+ class String
+ def speak
+ puts "hello #{self}"
+ end
+ end
- Add this to a file called ~/.irbrc:
+ b = "Tamer"
- <pre class="code">
- :::ruby
- class Object
- def pim inherited = false
- self.class.public_instance_methods(inherited).sort -
- Object.public_instance_methods
- end
- end
- </pre>
+ b.speak
- Now you can do stuff like:
+ class Duck < String
+ end
- $ irb
- >> "blah".pim
- => ["%", "*", "+", "<<", "<=>", "[]", "[]=", "bytes", "bytesize", ...]
+ c = Duck.new
+ c.speak
+
+
+
+
+explanation: |
+ * `some_hash = {1 => "Calgary", 2 => "Edmonton"}`
+ * creates a hash and assigns it to variable `some_hash`
+ * `some_hash.keys` and `some_hash.values`
+ * calls methods for this hash that returns a list of keys and values
+ * `some_hash.each ... end`
+ * Looks against the hash and displays the key and value
+ * the call `puts "Key is #{k}, Value is #{v}"` is equivalent to `puts "Key is " + k.to_s + ", Value is " + v.to_s
+ * `class Workshop...end`
+ * the Ruby way of defining a class
+ * `def size...end`
+ * the Ruby way of defining a method
+ * `class Duck < String ... end`
+ * the Ruby way of defining a class that inherits from another
- All of these methods are available for any string. You can then use
- `ri` to look up the method documentation. It is a great way to find goodies!
### online resources
- * [Ruby Quickref](http://www.zenspider.com/Languages/Ruby/QuickRef.html)
* The Google - searching "ruby" and whatever you're looking for usually leads to good stuff.
+ * [Ruby Quickref](http://www.zenspider.com/Languages/Ruby/QuickRef.html)
* [Ruby Koans](http://rubykoans.com/) - a great set of lessons in an interactive form.
* [Learn to Program by Chris Pine](http://pine.fm/LearnToProgram) - also available as [a book](http://pragprog.com/book/ltp2/learn-to-program).
* [The Pickaxe](http://pragprog.com/book/ruby3/programming-ruby-1-9) - The definitive ruby reference (and has a great tutorial too).
* [Why's (poignant) Guide to Ruby](http://www.scribd.com/doc/8545174/whys-Poignant-Guide-to-Ruby) - the (crazy) guide to ruby... Try it, you might like it.
+
+
View
@@ -15,8 +15,8 @@ steps: |
Open up a terminal window and try out the following.
- $ mkdir railsbridge
- $ cd railsbridge
+ $ mkdir calgary_rails
+ $ cd calgary_rails
$ rails new suggestotron
$ cd suggestotron
$ ls
@@ -26,9 +26,9 @@ steps: |
explanation: |
* 'mkdir' stands for make directory (folder).
- * We've made a folder called railsbridge
+ * We've made a folder called calgary_rails
* 'cd' stands for change directory.
- * 'cd railsbridge' makes railsbridge our current directory.
+ * 'cd calgary_rails' makes calgary_rails our current directory.
* 'rails new' creates a new rails project with the name you give.
* In this case we told it to create a new project called suggestotron.
* We'll go into detail on what it created shortly.
View
@@ -0,0 +1,57 @@
+content: |
+ ## Other Tools to help you learn Ruby
+
+ ### ri
+
+ ri is a tool to look up ruby documentation:
+
+ $ ri String.split
+ = String.split
+
+ (from ruby core)
+ ------------------------------------------------------------------------------
+ str.split(pattern=$;, [limit]) => anArray
+
+ ------------------------------------------------------------------------------
+
+ Divides str into substrings based on a delimiter, returning an array of
+ these substrings.
+ ...
+
+ You can do a lot with it:
+
+ * `ri Class` -- looks up the class documentation and shows all the methods available.
+ * `ri Class.method` -- looks up a specific method on a class or module.
+ * `ri method` -- searches all classes for matching methods
+
+ If running ri doesn't work and you've installed ruby using rvm, try
+ running this command first:
+
+ $ rvm docs generate
+
+ ### irb
+
+ We've already introduced irb above, but it can't be stressed enough
+ that having an interactive live session with ruby is invaluable. You
+ can learn a lot from it.
+
+ Add this to a file called ~/.irbrc:
+
+ <pre class="code">
+ :::ruby
+ class Object
+ def pim inherited = false
+ self.class.public_instance_methods(inherited).sort -
+ Object.public_instance_methods
+ end
+ end
+ </pre>
+
+ Now you can do stuff like:
+
+ $ irb
+ >> "blah".pim
+ => ["%", "*", "+", "<<", "<=>", "[]", "[]=", "bytes", "bytesize", ...]
+
+ All of these methods are available for any string. You can then use
+ `ri` to look up the method documentation. It is a great way to find goodies!

0 comments on commit 1271d57

Please sign in to comment.