Ruby is a dynamically typed object oriented programming language with both imperative and functional features. Ruby code is often interpreted but several systems perform native code generation too.
Here is an example of the 100 doors problem:
#!/usr/bin/env ruby
def doors n
# Initialize an array
doors = [false] * n
# Process the doors
(1..n).each do |inc|
(inc..n).step(inc) do |d|
doors[d] = !doors[d]
end
end
# Print out the results
doors.each_with_index do |b, i|
puts "Door \##{i} is #{b ? 'open' : 'closed'}."
end
end
# Call the doors function with n = 100
doors(100)
Ruby is a both powerful and easy to learn. It has a syntax which feels natural and is also very flexible.
Ruby is surrounded by a passionate community and there are a wide range of 3rd party libraries available. This makes it easy to develop new applications by relying on existing work.
Ruby is a cross platform development language with multiple implementations, including MRI (the default implementation), JRuby, IronRuby and Rubinius.