Search This Blog

Tuesday, February 21, 2006

Handy way of mapping values in Ruby

There is something I like about Ruby that you can do in some languages but not most languages.

Here is an example:

grade = case points
when 94..100 then :A
when 83..93 then :B
when 75..82 then :C
when 65..74 then :D
else :F
end


You can do something very similar in LISP using the COND function and in MUMPS using the $SELECT function. Most languages do not have something this convenient.

No comments: