Skip to content

Commit 06f99dd

Browse files
Jason ReevesJason Reeves
authored andcommitted
add lesson 1.1
1 parent 9490563 commit 06f99dd

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

examples/1.1.0.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
a = 1
2+
b = 4
3+
puts "The number #{a} is less than #{b}"

examples/1.1.1.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def string_length_interpolater(incoming_string)
2+
"The string you just gave me has a length of "
3+
end
4+
5+
puts string_length_interpolater("hello")

examples_spec/1.1.1.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'rspec'
2+
3+
describe "example code" do
4+
let(:output) { `#{RbConfig.ruby} __TMPFILE__`.chomp }
5+
6+
it "should be a string" do
7+
expect(output.is_a?(String)).to be(true)
8+
end
9+
10+
it "should equal 'The string you just gave me has a length of 5'" do
11+
expect(output).to eq("The string you just gave me has a length of 5")
12+
end
13+
end

lessons/1.1.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"subsections": [
3+
{
4+
"name": "String Basics",
5+
"items": [
6+
{
7+
"type": "header",
8+
"value": "String Interpolation"
9+
},
10+
{
11+
"type": "paragraph",
12+
"value": "It is essential to be able to replace placeholders within a string with values they represent. In the programming paradigm, this is called \"string interpolation\". In Ruby, string interpolation is extremely easy. Feel free to run the example below to see the sample in action."
13+
},
14+
{
15+
"type": "example",
16+
"value": "1.1.0"
17+
},
18+
{
19+
"type": "paragraph",
20+
"value": "Do remember that placeholders aren't just variables. Any valid block of Ruby code you place inside `#{}` will be evaluated and inserted at that location. Isn't that very neat?"
21+
},
22+
{
23+
"type": "paragraph",
24+
"value": "Now let us see you wield this tool. Complete the functionality of the method below which, given a `String` as the argument, inserts the length of that `String` into another `String`:"
25+
},
26+
{
27+
"type": "test_example",
28+
"value": "1.1.1"
29+
},
30+
{
31+
"type": "paragraph",
32+
"value": "We've been using double quotes in all our string interpolation examples. A `String` literal created with single quotes does _not_ support interpolation."
33+
},
34+
{
35+
"type": "paragraph",
36+
"value": "The essential difference between using single or double quotes is that double quotes allow for escape sequences while single quotes do not. What you saw above is one such example. `\"\\n\"` is interpreted as a new line and appears as a new line when rendered to the user, whereas `'\\n'` displays the actual escape sequence to the user."
37+
},
38+
{
39+
"type": "paragraph",
40+
"value": "Let us move on ..."
41+
}
42+
]
43+
}
44+
]
45+
}

lessons/toc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"0.0.json",
44
"0.1.json",
55
"0.2.json",
6-
"1.0.json"
6+
"1.0.json",
7+
"1.1.json"
78
]
89
}

0 commit comments

Comments
 (0)