Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
6
Task/Integer-comparison/Ruby/integer-comparison-1.rb
Normal file
6
Task/Integer-comparison/Ruby/integer-comparison-1.rb
Normal 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
|
||||
8
Task/Integer-comparison/Ruby/integer-comparison-2.rb
Normal file
8
Task/Integer-comparison/Ruby/integer-comparison-2.rb
Normal 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
|
||||
24
Task/Integer-comparison/Ruby/integer-comparison-3.rb
Normal file
24
Task/Integer-comparison/Ruby/integer-comparison-3.rb
Normal 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}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue