EvilZone
Programming and Scripting => Scripting Languages => : parad0x January 16, 2013, 04:07:16 AM
-
I read ande's tut on python and there I saw Dark Nebulae requesting for a Ruby tut.I asked to myself,"If I know Ruby(not perfectly),why can't I write a tut on getting started with Ruby."I didn't posted it in tut thread because it is a scripting language tut and it should be in the Scripting Language thread.The style of writing this tut is similar to the one written by ande on python scripting.Thanks to ande without whom I would not have written this tut in a simple way.Thanks ande.
Starting Ruby Scripting
--- A tut written by Mr. Perfect
1.) About Ruby-- According to wikipedia:
Ruby is a dynamic (http://en.wikipedia.org/wiki/Dynamic_programming_language), reflective (http://en.wikipedia.org/wiki/Reflection_%28computer_science%29), general-purpose object-oriented programming language (http://en.wikipedia.org/wiki/Object-oriented_programming_language) that combines syntax inspired by Perl (http://en.wikipedia.org/wiki/Perl) with Smalltalk (http://en.wikipedia.org/wiki/Smalltalk)-like features. It was also influenced by Eiffel (http://en.wikipedia.org/wiki/Eiffel_%28programming_language%29) and Lisp (http://en.wikipedia.org/wiki/Lisp_%28programming_language%29). Ruby was first designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto (http://en.wikipedia.org/wiki/Yukihiro_Matsumoto) in Japan (http://en.wikipedia.org/wiki/Japan).
Ruby supports multiple programming paradigms (http://en.wikipedia.org/wiki/Programming_paradigm), including functional (http://en.wikipedia.org/wiki/Functional_programming), object oriented (http://en.wikipedia.org/wiki/Object-oriented_programming), imperative (http://en.wikipedia.org/wiki/Imperative_programming) and reflective (http://en.wikipedia.org/wiki/Reflective_programming). It also has a dynamic type (http://en.wikipedia.org/wiki/Dynamic_type) system and automatic memory management (http://en.wikipedia.org/wiki/Memory_management); it is therefore similar in varying respects to Smalltalk (http://en.wikipedia.org/wiki/Smalltalk), Python (http://en.wikipedia.org/wiki/Python_%28programming_language%29), Perl (http://en.wikipedia.org/wiki/Perl), Lisp (http://en.wikipedia.org/wiki/Lisp_%28programming_language%29), Dylan (http://en.wikipedia.org/wiki/Dylan_%28programming_language%29), Pike (http://en.wikipedia.org/wiki/Pike_%28programming_language%29), and CLU (http://en.wikipedia.org/wiki/CLU_%28programming_language%29).
The standard 1.8.7 implementation (http://en.wikipedia.org/wiki/Ruby_MRI) is written in C (http://en.wikipedia.org/wiki/C_%28programming_language%29), as a single-pass interpreted language (http://en.wikipedia.org/wiki/Interpreted_language). The language specifications for Ruby were developed by the Open Standards Promotion Center of the Information-Technology Promotion Agency (a Japanese government (http://en.wikipedia.org/wiki/Government_of_Japan) agency) for submission to the Japanese Industrial Standards Committee and then to the International Organization for Standardization (http://en.wikipedia.org/wiki/International_Organization_for_Standardization). It was accepted as a Japanese Industrial Standard (JIS X 3017) in 2011[8] and an international standard (ISO/IEC 30170 (http://en.wikipedia.org/w/index.php?title=ISO/IEC_30170&action=edit&redlink=1)) in 2012.[9] As of 2010, there are a number of complete or upcoming alternative implementations of Ruby, including YARV (http://en.wikipedia.org/wiki/YARV), JRuby (http://en.wikipedia.org/wiki/JRuby), Rubinius (http://en.wikipedia.org/wiki/Rubinius), IronRuby (http://en.wikipedia.org/wiki/IronRuby), MacRuby (http://en.wikipedia.org/wiki/MacRuby) (and its iOS counterpart, RubyMotion (http://en.wikipedia.org/wiki/RubyMotion)), and HotRuby (http://en.wikipedia.org/wiki/HotRuby). Each takes a different approach, with IronRuby, JRuby, MacRuby and Rubinius providing just-in-time compilation (http://en.wikipedia.org/wiki/Just-in-time_compilation) and MacRuby also providing ahead-of-time compilation (http://en.wikipedia.org/wiki/Ahead-of-time_compilation). The official 1.9 branch uses YARV (http://en.wikipedia.org/wiki/YARV), as will 2.0 (development), and will eventually supersede the slower Ruby MRI (http://en.wikipedia.org/wiki/Ruby_MRI).
Even most of the meatsploit modules and exploits are written in ruby.
2.) Installing Ruby--[/b]
On windows,you can download the Ruby installer from http://www.softpedia.com/get/Programming/Coding-languages-Compilers/RubyInstaller.shtml (http://www.softpedia.com/get/Programming/Coding-languages-Compilers/RubyInstaller.shtml)
On deb linux,with APT installed,type sudo apt-get install ruby.
To check if Ruby is installed correctly or not(in windows) open cmd and execute irb.
If you see something like this C:\windows\system32>irb
irb(main):001:0>
This means you have installed it correctly. :)
On linux,execute irb in the terminal.If you see something like this
root@bt:~# irb
irb(main):001:0>
You are going right way. ;)
Starting scripting--
Scripting in Ruby is somewhat like python.Create ruby files with .rb extension and to run the file navigate to that directory and type "ruby <filename>.rb".Lets start now
Hello world in Ruby:
print "Hello World!"
Printing variables:
var1 = "Hello world!"
print var1
Doing some maths:
num1 = 15
num2 = 20
num3 = 25
sum = num1 + num2 + num3
print sum
OUTPUT:
60
Some sites which teach Ruby in interactive way:
http://rubymonk.com (http://rubymonk.com)
http://www.codecademy.com/tracks/ruby (http://www.codecademy.com/tracks/ruby)
http://tryruby.org (http://tryruby.org)
And an excellent source for those who want some more sites:
http://iwanttolearnruby.com/ (http://iwanttolearnruby.com/)
Note for the beginners: I would suggest using irb first before you move on the files.Learn irb because it shows how ruby works.
-
A very good Ruby tut. I think I should take Ruby as my first language.