-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1vars.rb
More file actions
29 lines (22 loc) · 886 Bytes
/
Copy path1vars.rb
File metadata and controls
29 lines (22 loc) · 886 Bytes
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
# The puts method enables to write to console.
# Note that like other methods in ruby, parenthesis are optional
# Using single quotes, backslashes are ignored.
puts 'Hello, World!\nRuby is fun !'
puts "Hello, World!\nRuby is fun !"
puts('Another one with parenthesis')
puts 3*3 # 9
puts "3"*3 # 333, string multiplication is possible
# The .to_i method here is transforming a string to an integer.
# Note that if there is no arguments, parenthesis are optional.
puts "3".to_i * 3 # 9
name = 'Baba'
name = 3 # variables are dynamic
puts 'Name is ' + name.to_s
# String interpolation
# Note that string interpolations are only working with double quoted expressions
puts "3 times 4 equal #{3*4}" # 3 times 4 equal 12
# To get console inputs, use the gets method
puts "What is your name ? "
guest = gets
# To remove line-breaks in gets string, use the gets.chomp
puts "Hi, #{guest}"