Universal Code Snippet
puts "Hello, World!"print "Enter your name: "
name = gets.chomp
puts "Hello, #{name}!"age = 20
if age >= 18
puts "You are an adult."
else
puts "You are a minor."
endputs "For loop:"
(1..5).each { |i| print "#{i} " }
puts
puts "While loop:"
j = 1
while j <= 5
print "#{j} "
j += 1
end
putsdef add(a, b)
a + b
end
puts "Sum: #{add(10, 20)}"numbers = [10, 20, 30, 40, 50]
numbers.each_with_index do |v, i|
puts "Element #{i}: #{v}"
endstr1 = "Hello"
str2 = " World"
puts "Length: #{str1.length}"
combined = str1 + str2
puts "Concatenated: #{combined}"
puts "Uppercase: #{combined.upcase}"a, b = 15.0, 4.0
puts "Add: #{a + b}"
puts "Subtract: #{a - b}"
puts "Multiply: #{a * b}"
puts "Divide: #{a / b}"