This repository has been archived by the owner on Mar 10, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
381 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
!SLIDE subsection | ||
# Data Types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,28 @@ | ||
!SLIDE subsection | ||
# `nil` | ||
|
||
|
||
!SLIDE | ||
# nil | ||
# `nil` | ||
|
||
@@@ Ruby | ||
# nil is the Ruby value for null | ||
var = nil | ||
|
||
# Check if the value is nil | ||
var.nil? | ||
# => true | ||
|
||
# Alternative version, almost never used | ||
var == nil | ||
# => true | ||
|
||
|
||
!SLIDE | ||
# `nil` | ||
|
||
@@@ Ruby | ||
|
||
# nil evaluates to false | ||
nil ? true : false | ||
# => false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,15 @@ | ||
!SLIDE subsection | ||
# Boolean | ||
|
||
|
||
!SLIDE | ||
# Boolean | ||
|
||
@@@ Ruby | ||
var = true | ||
|
||
if var | ||
# var is true | ||
else | ||
# var is false | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,103 @@ | ||
!SLIDE subsection | ||
# String | ||
|
||
|
||
!SLIDE | ||
# String | ||
|
||
@@@ Ruby | ||
var = 'string' | ||
var = "string" | ||
|
||
var = %q{string} | ||
var = %Q{string} | ||
|
||
var = <<-EOS | ||
long | ||
string | ||
EOS | ||
|
||
|
||
!SLIDE | ||
# String | ||
## The Ruby way | ||
|
||
@@@ Ruby | ||
# Rubyists do not use \ to escape | ||
# because it makes the code hard to read | ||
var = "<a href=\"\#hello\">I'm a tag</a>" | ||
|
||
# They prefer a more natural syntax | ||
var = %q{<a href="#hello">I'm a tag</a>} | ||
|
||
|
||
!SLIDE | ||
# String | ||
## Interpolation | ||
|
||
@@@ Ruby | ||
who = "world" | ||
|
||
var = 'hello #{who}' | ||
# => hello #{who} | ||
|
||
var = "hello #{who}" | ||
# => hello world | ||
|
||
var = %q{hello #{who}} | ||
# => hello #{who} | ||
|
||
var = %Q{hello #{who}} | ||
# => hello world | ||
|
||
|
||
!SLIDE | ||
# String | ||
## Escape sequences | ||
|
||
@@@ Ruby | ||
|
||
var = 'hello\nworld' | ||
# => hello\nworld | ||
|
||
var = "hello\nnworld" | ||
# => hello | ||
world | ||
|
||
var = %q{hello\nnworld} | ||
# => hello\nnworld | ||
|
||
var = %Q{hello\nnworld} | ||
# => hello | ||
world | ||
|
||
|
||
!SLIDE | ||
# String | ||
## % Notation | ||
|
||
@@@ Ruby | ||
|
||
"I love %s" % "Ruby" | ||
# => "I love Ruby" | ||
|
||
"I prefer %s over %s" % ["Ruby", "Java"] | ||
# => "I prefer Ruby over Java" | ||
|
||
vars = { :a => "Ruby", :b => "Java" } | ||
"I prefer %{a} over %{b}. I love %{a}!" % vars | ||
# => "I prefer Ruby over Java. I love Ruby!" | ||
|
||
|
||
!SLIDE | ||
# String | ||
|
||
@@@ Ruby | ||
|
||
# empty string evaluates to true | ||
"" ? true : false | ||
# => true | ||
|
||
# not-empty string evaluates to true | ||
"string" ? true : false | ||
# => true |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
!SLIDE subsection | ||
# Sumbol | ||
|
||
|
||
!SLIDE | ||
# Symbol | ||
|
||
@@@ Ruby | ||
var = :foo | ||
|
||
var | ||
# => :foo | ||
|
||
var.to_s | ||
# => "foo" | ||
|
||
|
||
!SLIDE | ||
# Symbol | ||
|
||
@@@ Ruby | ||
:foo == :"foo" | ||
# => true | ||
|
||
:foo == "foo".intern | ||
# => true | ||
|
||
:foo == "foo".to_sym | ||
# => true | ||
|
||
|
||
!SLIDE | ||
# Symbol | ||
|
||
@@@ Ruby | ||
var = "Simone" | ||
|
||
var.respond_to?(:upcase) | ||
# => true | ||
|
||
var.send(:upcase) | ||
# => "SIMONE" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
!SLIDE subsection | ||
# Number | ||
|
||
|
||
!SLIDE | ||
# Number | ||
|
||
@@@ Ruby | ||
# Fixnum | ||
1 | ||
-1 | ||
|
||
# Float | ||
1.0 | ||
|
||
# The following two objects are equal | ||
1000000 | ||
1_000_000 | ||
|
||
|
||
!SLIDE | ||
# Number | ||
|
||
@@@ Ruby | ||
|
||
# 0 evaluates to true | ||
0 ? true : false | ||
# => true | ||
|
||
# not-0 evaluates to true | ||
10 ? true : false | ||
# => true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
!SLIDE subsection | ||
# Array | ||
|
||
|
||
!SLIDE | ||
# Array | ||
|
||
@@@ Ruby | ||
var = Array.new | ||
# => [] | ||
|
||
var = ["foo", "bar", "baz"] | ||
# => ["foo", "bar", "baz"] | ||
|
||
var = [ | ||
"foo", | ||
"bar", | ||
"baz", | ||
] | ||
# => ["foo", "bar", "baz"] | ||
|
||
var = %w( foo bar baz ) | ||
# => ["foo", "bar", "baz"] | ||
|
||
|
||
!SLIDE | ||
# Array | ||
|
||
@@@ Ruby | ||
var = ["foo", 0, "baz"] | ||
|
||
var = ["foo", ["bar", "baz"]] | ||
|
||
|
||
!SLIDE | ||
# Array | ||
|
||
@@@ Ruby | ||
var1 = %w( yellow orange ) | ||
var2 = %w( red yellow ) | ||
|
||
var1.size | ||
# => 2 | ||
|
||
var1[1] = "blue" | ||
# => blue | ||
|
||
var1 + var2 | ||
# => ["yellow", "blue", "red", "yellow"] | ||
|
||
|
||
!SLIDE | ||
# Enumerable | ||
|
||
@@@ Ruby | ||
var1 = %w( yellow orange red ) | ||
|
||
var1.each { |color| p(color) } | ||
# => yellow | ||
# => orange | ||
# => red | ||
|
||
var1.map { |color| color.upcase } | ||
# => ["YELLOW", "ORANGE", "RED"] | ||
|
||
var1.select { |color| color.size == 3 } | ||
# => ["red"] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
!SLIDE subsection | ||
# Hash | ||
|
||
|
||
!SLIDE | ||
# Hash | ||
|
||
@@@ Ruby | ||
var = {} | ||
# => {} | ||
|
||
var = { "foo" => 1, "bar" => 2 } | ||
var = { :foo => 1, :bar => 2 } | ||
|
||
|
||
!SLIDE | ||
# Hash | ||
|
||
@@@ Ruby | ||
var = { :foo => 1, :bar => 2 } | ||
|
||
var[:baz] | ||
# => nil | ||
|
||
var[:foo] | ||
# => 1 | ||
|
||
var[:foo] = 2 | ||
# => 2 | ||
|
||
var["foo"] | ||
# => nil |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.