I'm doing this course for fun since I'm a Ruby enthusiastic! This material is under construction.
-
Everything is an object
p 1.methods p 2.between? 1,3 p 2.even? p 1+2 p 1.+(2) p 3 == 3
-
Types
name = 'Daniel' # Strings age = 42 # Integer weight = 89.9 # Float is_tall = true # Boolean
-
Calculations
puts 2 * 3 # Basic Arithmetic: +, -, /, * puts 2**3 # Expoent puts 10 % 3 # Modulus puts 1 + 2 * 3 # Order of operation puts 10 / 3 # Float
-
Iteration with +=, -=, /=, *=
num = 1 num += 10
-
Setting values
sum = 1 + 2 a, b = 1, 2 name = 'Daniel' res = 1 > 2 ? true : false c, d, e = [1, 2, 3]
-
Basics
greeting = 'Hello Ruby' puts greeting.size puts greeting[0] puts greeting.include? 'Ruby' puts greeting[1, 3] puts greeting[-1, -4]
-
Interpolation
a = 1 b = 4 puts "The number #{a} is less than #{b}"
-
Search in strings
"[Luke:] I can’t believe it. [Yoda:] That is why you fail.".include? 'Yoda' "Ruby is a beautiful language".start_with? 'Ruby' "I can't work with any other language but Ruby".end_with? 'Ruby' "I am a Rubyist".index 'R'
-
Replace
"I should look into your problem when I get time".sub('I','We') "I should look into your problem when I get time".gsub('I','We') 'RubyIsGreat'.gsub(/[aeiou]/,'1') 'Ruby Is Pretty Brilliant'.gsub /[A-Z]/, '0'