Contents |
Utility Ruby - Object-Oriented Ruby - Ruby Tricks - Ruby and Vim - Rake - Ruby on Rails - Ruby UI - Parse XML in Ruby - Ruby Web Spider
s = lambda { |x| x.gsub!(/-/,'-=-') }
t = '-'
5.times{ s.call(t) }
puts t
ruby -e 'command;command' execute one line of Ruby code ruby program.rb execute Ruby program ruby -pe 'gsub(/regex/,"replacement")' like sed ruby -pi 'gsub(/regex/,"replacement")' file like 'sed -i' (in-place) irb interactive ruby shell ri -c list all Ruby classes known to ri ri Dir.open get documentation for Dir.open
I like ruby, because it's intuitive, concise and very object-oriented.
Just to prove my point, check out the shortest fully functional 3D vector class I have ever written in any language.
class Vector
attr_reader :x, :y, :z
def initialize(x, y, z) @x, @y, @z = x, y, z end
def to_s
("(%+4.2f, %+4.2f, %+4.2f)" % [@x, @y, @z]).gsub(/\+/, " ")
end
def +(o) Vector.new(@x + o.x, @y + o.y, @z + o.z) end
def -(o) Vector.new(@x - o.x, @y - o.y, @z - o.z) end
def *(o)
case o
# scalar multiplication
when Numeric then Vector.new(@x * o, @y * o, @z * o)
# dot product
when Vector then o.x * @x + o.y * @y + o.z * @z
end
end
def ==(o) @x == o.x and @y == o.y and @z == o.z end
end
It has 'get'-methods for the elements, constructor, string output, addition, subtraction, scalar multiplication, dot product, and equality...
Ruby has third-party support for unit testing, mySQL, OpenGL, among others.
Try RubyScript2Exe. It packs all the necessary libraries into a single executable, and it works both on Linux and Windows.
Check out this Windows executable made with RubyScript2Exe.
* NOTE: When running the program, you must end the simulation by pressing a key, and not by closing the window. There's a bug in the OpenGL for Ruby implementation, it doesn't handle closing of the window, and a 'rubyw.exe' process will keep running, eating all your processing power. Anyways, if you forget, you can always just kill rubyw with ctrl+shift+esc.
The following 19 pages are in this category, out of 19 total.
ACINO |
O cont.R |
R cont.SUV |