Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,6 @@
a = (print "enter a value for a: "; gets).to_i
b = (print "enter a value for b: "; gets).to_i
puts "#{a} is less than #{b}" if a < b
puts "#{a} is greater than #{b}" if a > b
puts "#{a} is equal to #{b}" if a == b

View file

@ -0,0 +1,8 @@
a = (print "enter a value for a: "; gets).to_i
b = (print "enter a value for b: "; gets).to_i
case a <=> b
when -1; puts "#{a} is less than #{b}"
when 0; puts "#{a} is equal to #{b}"
when +1; puts "#{a} is greater than #{b}"
end

View file

@ -0,0 +1,24 @@
# Function to make prompts nice and simple to abuse
def prompt str
print str, ": "
gets.chomp
end
# Get value of a
a = prompt('Enter value of a').to_i
# Get value of b
b = prompt('Enter value of b').to_i
# The dispatch hash uses the <=> operator
# When doing x<=>y:
# -1 means x is less than y
# 0 means x is equal to y
# 1 means x is greater than y
dispatch = {
-1 => "less than",
0 => "equal to",
1 => "greater than"
}
# I hope you can figure this out
puts "#{a} is #{dispatch[a<=>b]} #{b}"