Skip to content

Commit 21ab99b

Browse files
janetrileydshafik
authored andcommitted
Adding RailsBridge Boston 1.2014 ruby workshop mods
Modifications include: * fleshing out all the sites/ruby workshop content -- janetriley, mxie, dpickett * Adding the 'challenge' tag to the dsl -- dpickett
1 parent 7b06d52 commit 21ab99b

18 files changed

+1072
-0
lines changed

lib/step.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def insert file
5858
overview:"Overview",
5959
discussion:"Discussion Items",
6060
hints:"Hints",
61+
challenge:"Challenge(s)",
6162
tools_and_references:"Tools and References",
6263
requirements:"Requirements to advance",
6364
}

public/css/step.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ table.bordered tr {
141141
.explanation > h1:before,
142142
.deploying > h1:before,
143143
.overview > h1:before,
144+
.challenge > h1:before,
144145
.further-reading > h1:before {
145146
content: "\00a0";
146147
display: inline-block;

sites/en/ruby/booleans.step

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
message "George Boole was an English mathematician who specialized in logic,
2+
especially logic rules involving true and false. The Boolean datatype
3+
is named in his honor.
4+
5+
In code, as in life, we base a lot of decisions on whether something is true or
6+
false. *\"If it is raining, then I will bring an umbrella; otherwise I will wear
7+
sunglasses.\"* In the conditionals section we'll make decisions. First we need to look at true and false."
8+
9+
goals do
10+
goal "Meet True and False"
11+
goal "Compare numbers and strings"
12+
goal "Evaluate 'and', 'or', and 'not' logic"
13+
goal "Understand methods ending with question marks (predicates)"
14+
end
15+
16+
17+
step do
18+
message 'Here are some expressions that return `true` or `false`:'
19+
irb <<-IRB
20+
15 < 5
21+
15 > 5
22+
15 >= 5
23+
10 == 12
24+
IRB
25+
end
26+
27+
28+
step do
29+
message 'Notice we use a double equals sign to check if things are equal. It\'s a common mistake to use a single equals sign.'
30+
irb <<-IRB
31+
a = 'apple'
32+
b = 'banana'
33+
a == b
34+
puts a + b
35+
a = b
36+
puts a + b
37+
IRB
38+
message "Surprise!"
39+
end
40+
41+
step do
42+
message "For 'not equals', try these:"
43+
irb <<-IRB
44+
a = 'apple'
45+
b = 'banana'
46+
a != b
47+
IRB
48+
message "The exclamation point means **the opposite of**"
49+
irb <<-IRB
50+
!true
51+
!false
52+
!(a == b)
53+
IRB
54+
message "In `!(a == b)`, Ruby first evaluated `a == b`, then gave the opposite."
55+
message "It also means **not true** . In conditionals, we'll see things like
56+
57+
58+
if not sunny
59+
puts \"Bring an umbrella!\"
60+
61+
We can also say
62+
63+
if sunny == false
64+
puts \"Bring an umbrella!\"
65+
but \"if not sunny\" is a little more natural sounding. It's also a little safer
66+
- that double equals is easy to mistype as a single equals."
67+
end
68+
69+
step do
70+
message "We can check more than one condition with `and` and `or` . `&&` and `||` (two pipes) is another notation for `and` and `or`."
71+
message "We do something like this when we Google for 'microsoft and cambridge and not seattle'"
72+
irb <<-IRB
73+
# First let's define variables:
74+
yes = true
75+
no = false
76+
# Now experiment. Boolean rule 1: AND means everything must be true.
77+
# true and true are true
78+
yes and yes
79+
yes && yes
80+
# true and false fail the test - AND means everything must be true
81+
yes and no
82+
no and yes
83+
no and no
84+
# Boolean rule 2: OR says at least one must be true.
85+
yes or no
86+
yes || no
87+
yes or yes
88+
IRB
89+
end
90+
91+
92+
step do
93+
message 'By convention, methods in Ruby that return booleans end with a question mark.'
94+
irb <<-IRB
95+
'sandwich'.end_with?('h')
96+
'sandwich'.end_with?('z')
97+
[1,2,3].include?(2)
98+
[1,2,3].include?(9)
99+
'is my string'.empty?
100+
''.empty?
101+
'is this nil'.nil?
102+
nil.nil?
103+
IRB
104+
end
105+
106+
107+
explanation do
108+
message "In code we ask a lot of questions. Boolean logic gives us tools to express the questions. "
109+
end
110+
111+
further_reading do
112+
message "Some languages offer wiggle room about what evaluates to true or false. Ruby has very little. See [What's Truthy and Falsey in Ruby?](https://gist.github.com/jfarmer/2647362)"
113+
message "[What's Truthy and Falsey in Ruby?](https://gist.github.com/jfarmer/2647362) has a more detailed walkthrough of booleans."
114+
message "Ruby documentation for [true](http://www.ruby-doc.org/core-2.1.0/TrueClass.html) and [false]](http://www.ruby-doc.org/core-2.1.0/TrueClass.html)"
115+
end
116+
117+
next_step "conditionals"

sites/en/ruby/classes.step

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
goals do
2+
goal "Define a new object"
3+
goal "Create an instance of your object"
4+
goal "Call methods on your object"
5+
end
6+
7+
step do
8+
message 'Create a new file called circle.rb'
9+
type_in_file 'circle.rb', <<-'CONTENTS'
10+
class Circle
11+
def initialize(radius)
12+
@radius = radius
13+
end
14+
15+
def area
16+
Math::PI * (@radius ** 2)
17+
end
18+
19+
def perimeter
20+
2 * Math::PI * @radius
21+
end
22+
end
23+
24+
print "What is the radius of your circle? > "
25+
radius = gets.to_i
26+
27+
a_circle = Circle.new(radius)
28+
puts "Your circle has an area of #{a_circle.area}"
29+
puts "Your circle has a perimeter of #{a_circle.perimeter}"
30+
CONTENTS
31+
console 'ruby circle.rb'
32+
message 'When prompted, type in a radius for your circle.'
33+
end
34+
35+
explanation do
36+
message "Functions by themselves aren't always enough to keep your program organized. **Object-oriented programming** was developed to keep related data (attributes) and functions that work on that data (methods) together."
37+
message "In Ruby, a new object is defined with the **class** keyword, followed by the name of your object (typically CamelCased). You finish the object definition later on with an **end**."
38+
message "Most objects define a special method, **initialize**, that saves the initial data your object is created with (here, a radius) and performs any other required set-up."
39+
message "You create an **instance** of your object with the **new** method. Arguments passed in to **new** are sent to your **initialize** method."
40+
message "Data is stored on your object using **instance variables** that start with an `@` sign. Instance variables behave like normal variables, but are only visible from inside a specific instance of your object. If you want the data to be externally accessible, you have to write more methods."
41+
end
42+
43+
next_step 'summary:_organizing'

sites/en/ruby/datatypes.step

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
goals do
2+
goal "Know the basic data types"
3+
goal "Know why it matters"
4+
message "Variables are easygoing about the objects they hold. You can assign a word, then assign a number, then a list of words."
5+
message "But sometimes it matters what type of data we assign a variable. The fancy word for \"type of data\" is **class**."
6+
message "Ruby has several built-in classes. In a later section, we'll explore how to make your own classes."
7+
end
8+
9+
step do
10+
message "How can you find out what class something is?"
11+
irb '"Letters and words".class'
12+
result "String"
13+
message "\"class\" is a **method**, a behavior you can ask an object to perform. "
14+
message "To call a method on an object, type the object or variable name, then
15+
a period, and finally the method name. "
16+
message "Here's a preview of the datatypes we'll cover:"
17+
irb <<-TRYME
18+
'a'.class
19+
5.class
20+
3.14.class
21+
true.class
22+
:symbol.class
23+
[ 1, 2, 3].class
24+
{name: "value"}.class
25+
nil.class
26+
Class.class
27+
TRYME
28+
end
29+
30+
step do
31+
message "Different classes come with different methods. Browse the String
32+
class' methods. (Ruby will put a ':' before the method name.)"
33+
irb '"five".methods'
34+
message "There are a lot of them. Can you predict what some of them do?"
35+
message "Numbers have different methods."
36+
irb "5.methods"
37+
message "Notice that number methods include arithmetic operators."
38+
message "Knowing what class an object is tells us what methods we can call."
39+
end
40+
41+
step do
42+
message "Some datatypes are incompatible. For example, Ruby knows how to
43+
concatenate two objects of the same class."
44+
irb <<-TRYME
45+
5 + 5
46+
"5" + "5"
47+
TRYME
48+
message "Ruby can guess how to convert some classes into a similar class."
49+
irb "5 + 5.0"
50+
message "... but it's totally confused by different objects."
51+
irb <<-TRYME
52+
5 + "5"
53+
"5" + 5
54+
TRYME
55+
end
56+
57+
step do
58+
message "When you have incompatible data types, you can use an object's
59+
*conversion methods* to get a translated version of the object."
60+
message "Conversion methods can be spotted by their name; they begin with
61+
`to_`, e.g. `to_s` converts to a string, `to_i` to an integer, and `to_f` to
62+
a float (decimal)."
63+
irb <<-TRYME
64+
5.to_s
65+
5.to_s.class
66+
5.to_f
67+
5.to_f.class
68+
5.67.to_i
69+
"5".to_i
70+
"5".to_i.class
71+
TRYME
72+
message "There isn't always a sensible conversion from one class to another."
73+
irb <<-TRYME
74+
"I am not a number".to_i
75+
"five".to_i
76+
TRYME
77+
message "Conversion methods are used most often in calculations and in printing."
78+
irb <<-TRYME
79+
5 + "5".to_i
80+
"5 plus" + 5.to_s
81+
TRYME
82+
message "It's common to include a `to_s` method when you make your own classes so it prints nicely."
83+
message "To explore further, try converting the examples in step 1 to
84+
different classes. To more easily see what conversion methods an object has,
85+
call `methods.sort` on it."
86+
irb "5.methods.sort"
87+
end
88+
89+
explanation do
90+
message "Sometimes it's necessary to think about what type of data you're working with."
91+
message "Use the `class` method to find out what class an object is."
92+
message "Use the `methods` method to find out what methods an object has."
93+
message "Use conversion methods to get a transformed version of an object."
94+
message "A `TypeError` message is a hint to look more carefully at an object's class."
95+
message "Let's look at the basic datatypes in more detail."
96+
end
97+
98+
next_step "strings"

sites/en/ruby/getting_help.step

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
goals do
3+
goal "Know where to find Ruby documentation"
4+
goal "Read an error message"
5+
goal "Meet StackOverflow"
6+
end
7+
8+
message do
9+
end
10+
11+
step do
12+
end
13+
14+
step do
15+
end
16+
17+
step do
18+
end
19+
20+
next_step "summary:_tools"

0 commit comments

Comments
 (0)