10/08/2008

Range Type in Ruby

Ruby has fifth principle types.
These are integer, string, array, hash and range.


I have not seen range type, First I see it in Ruby program.

Range type is very useful.
For example, when you use case sequence, you feel that range type is convenience.

The way is as next codes


case Time.now.hour # get now time
when 6..9 # use range type
puts "Good Morning"
when 9..17
puts "Hello"
when 17..6
puts "Good night"
else
puts "What?" # nothing time
end

No comments: