5. Everything is an object
• Really
1 20.to_s # "20"
2
3 100.times do
4 puts "100 is an object"
5 end
6 # "100 is an object", "100 is an object"
6. Dynamic language
• Some actions happens at runtime
9 class Person
10 def say_hello 21 p = Person.new
11 "hello" 22 p.say_hello
12 end 23 # hello
13 end 24 p.say_goodye
14 25 # goodbye
15 class Person
16 def say_goodye
17 "goodbye"
18 end
19 end
7. Methods
8 def my_method(arg, arg2="default")
9 "always returning the last line"
10 end
8. Control structures
30 if a > b 40 result = if a > b
31 "a is greater than b" 41 "a is greater than b"
32 else 42 else
33 "a isnt greater than b" 43 "a isnt greater than b"
34 end 44 end
10. Symbols
• A symbol is something that you use to
represent names. What this boils
down to is a way to efficiently have
descriptive names while saving the
space one would use to generate a
string for each naming instance.
12. Blocks/Procs
• Way to pass around chunks of code
51 def new_method(arg="default", &block)
52 puts "the arg is: #{arg}"
53 block.call
54 end
55
56 new_method do
57 puts "Callback"
58 end
59
60 # the arg is: default
61 # Callback