The Ruby program takes more time because it is not optimised and it also checks for numeric overflow. The following Ruby program
puts (1 .. 21).inject :*
will output "51090942171709440000". And puts (1 .. 21).inject(:*).class
will output "Bignum" because Ruby switches to big numbers when its integer representation is exceeded.