So what is Ruby?
Ruby is a strong Object Oriented language with several functional features available for use. It's heavily inspired by Perl, Smalltalk, and LISP, making it a hybrid language.
To quote the creator of Ruby, Yukihiro Matsumoto (Matz): "I wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. That's why I decided to design my own language."
The entire concept of Ruby is based around the philosophy that programming languages are for humans to be easily able to read. Considering most time spent in programming environments is reading code, I can sympathize quite strongly with this sentiment.
So how does Ruby achieve this bold claim? Take a look at a few snippets:
array = %w(timelord cybermen dalek who tardis screwdriver)
array.include?('timelord') # true
array.empty? # false
array.count # 6
The use of the question mark is one distinctive feature of Ruby that has made boolean tests far more readable and easily understood at a glance.
So where is Ruby used?
Ruby is used in multiple places from SysAdmin tasks, to Web Development (Rails, Sinatra, etc), to Development. It's a multi use language.
At $WORK (at the time of posting this) we use Ruby to test and maintain over 900 wireless antennas, audit systems, and check for validity against the databases to alert us of discrepancies in conjunction with monitoring software.
What type of power does it have?
Given the functional parts of Ruby, and its hybrid nature, its power is only limited to what types of insanity you can possibly conjure up.
Metaprogramming is one of the defining features of Ruby. It gives you the ability to:
- Dynamically Define Methods
- Dynamically Call Methods
- Overwrite Base Classes
- Instance Evaluation
- Overwrite Calls for a Missing Method
- ...and more
It includes closures, first class functions, tail call recursion (when enabled), blocks, procs, lambdas, and multiple other functional techniques.
In Ruby (almost) everything is an object, and it can be redefined. Everything can be monkeypatched (though not encouraged) and you can add methods to the kernel or object itself.
Some of the greatest power comes from its dynamic metaprogramming in conjunction with the above, such as threading:
require 'timeout'
require 'socket'
require 'win32/sound'
include Win32
ip = ARGV[0] ? ARGV[0] : '127.0.0.1'
puts "Invalid IP, defaulting to localhost: #{ip}" if ip == '127.0.0.1'
sleep 2 if ip == '127.0.0.1'
number = ARGV[1] ? ARGV[1].to_i : 50
i = 0
def ping(ip)
return system("ping -n 1 -w 1000 #{ip} > NUL")
end
def thread(method_name,ip,number)
threads = []
cmethod = method(method_name)
results = 0
number.times do
threads << Thread.new{results += 1 if cmethod.call(ip)}
end
threads.each {|t| t.join}
return results
end
while 1 == 1 do
beginning = Time.now
results = thread('ping',ip,number)
puts "#{results} out of #{number} clear"
puts Time.now - beginning
Sound.beep(3000, 500) unless results/number.to_f >= 0.9
end
The above demonstrates a few interesting things about Ruby. The method.call can call a method by name, allowing for dynamic calls, and in this case mass generation of threads to achieve a task. The next thing to notice is the post-testing with ifs that allows you to do an inline test to determine execution.
Who should use it?
Everyone should consider Ruby at some point. I would say it was the greatest bridge for me to enter into functional programming, and has really helped me get a grasp on more advanced languages in that realm.
I've come from a .NET and C# background, and Ruby was one of the most refreshing experiences I've had with programming.
Give it a shot, and see what you think!
http://www.ruby-lang.org/en/downloads/
This post has been edited by Skaggles: 05 August 2012 - 05:06 AM

New Topic/Question
Reply






MultiQuote






|