Ruby 1.8.5
Version of implementation Ruby of programming language RubyThis release includes changes related to non-blocking IO, Process.getrlimit/setrlimit
, RSS, documentation and other.
Examples:
Factorial - Ruby (62):
This example uses recursive factorial definition.
#! /usr/bin/env ruby
def factorial(n)
if n == 0
1
else
n * factorial(n - 1)
end
end
0.upto(16) do |n|
print(n, "! = ", factorial(n), "\n")
end
Factorial - Ruby (138):
This example uses an iterative factorial definition.
def fact(n)
(1..n).inject(1) {|a,b| a*b}
end
(0..16).each {|x| puts "#{x}! = #{fact(x)}"}
Fibonacci numbers - Ruby (156):
This example uses recursive definition of Fibonacci numbers.
#! /usr/bin/env ruby
def fibonacci(n)
if n < 3
1
else
fibonacci(n - 1) + fibonacci(n - 2)
end
end
(1..16).each {|n| puts fibonacci(n)}
puts "..."
Hello, World! - Ruby (157):
puts "Hello, World!"
Comments
]]>blog comments powered by Disqus
]]>