-
Notifications
You must be signed in to change notification settings - Fork 1
/
movies.rb
72 lines (43 loc) · 1.2 KB
/
movies.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
movies = [
{ :name => "Aeon Flux" },
{ :name => "Batman" },
{ :name => "Captain America" }
]
movies.each do |movie|
puts "#{movie[:name]} was a fantastical film."
end
# ---
name = "Alice"
# Concatenation
"Hello, " + name + "!"
# Interpolation
"Hello, #{name}!"
# ---
hello = "Hello"
Hello = "Hello"
"FooBar" # => Camel Case
"fooBar" # => variation of Camel Case
"foo_bar" # => Snake Case
["foo", "bar"]
# foo = "foo"
# bar = "bar"
[foo, bar] # => undefined `foo`.
h = { :foo => "foo", :bar => "BAR" }
h[:foo] # -> "foo"
# Array of Hashes
data = [
{ :name => "Apple", :taste => "Sweet" },
{ :name => "Banana", :taste => "Lovely", :color => "Yellow" },
{ :name => "Cactus", :taste => "Horrible" }
]
apple = data[0] # => { :name => "Apple", :taste => "Sweet" }
apple[:name] # => "Apple"
# Hash of Hashes (nested hashes)
fruit = {
:apple => { :name => "Apple", :taste => "Sweet" },
:banana => { :name => "Banana", :taste => "Lovely", :color => "Yellow" },
:cactus => { :name => "Cactus", :taste => "Horrible" },
0 => { :zero => "cool" }, # THIS IS A WEIRD THING TO DO: fruit[0]
"string" => "value" # DEMONSTRATION PURPOSES ONLY
}
fruit[:apple][:taste]