puts "Put numbers"
n = gets.to_i
if n.even?
puts "Is an even number"
else n.odd?
puts "Is odd"
end
to_i to_s
gets is saved as a string. To convert to a number → gets.to_i
each_with_index
fruits=["Apple","melon","Strawberry"]
fruits.each_with_index do |fruit, i|
puts “#{i+1}The second element is#{fruit}is. ”
end
【result】
The first element is the apple.
The second element is the melon.
The third element is strawberries.
http://vatscy.github.io/blog/2014/03/30/git-branch-stash/
Recommended Posts