Ranges as Conditions:
score = 45
case score
when 0..40
puts "Fail"
when 41..60
puts "Pass"
when 61..70
puts "Pass with Merit"
when 71..100
puts "Pass with Distinction"
else "Invalid Score"
end
Ranges as Intervals:
if ((1..10) === 5)
puts "5 lies in (1..10)"
end
if (('a'..'j') === 'c')
puts "c lies in ('a'..'j')"
end
if (('a'..'j') === 'z')
puts "z lies in ('a'..'j')"
else
puts "z Doesn't lie in ('a'..'j')"
end
No comments:
Post a Comment