Showing posts with label automation in ruby. Show all posts
Showing posts with label automation in ruby. Show all posts

Monday, November 10, 2014

Ruby for Beginners : The Basics

Ruby is a dynamic, reflective, object-oriented, general-purpose programming language. It's very simple and easy to learn. So, this is a tutorial for beginners in which I shall be covering the basics of Ruby and gradually more tutorials will be posted.

If you have not yet already installed the Ruby on your machine, you can refer the Installation steps in this article to download the setup and starting coding.

Interactive Ruby is the smartest way for the beginners to start learning Ruby. It can be opened from the Start Menu of your Windows under the Ruby section, after the installation is complete. In case of Mac OS and Linux, you can open up the Terminal(Mac) or shell(Linux) and type the command irb and hit enter. Something like the below should be displayed when you open it.
irb(main):001:0>
Now, when any value is entered whether a number or a string, Ruby returns some value. Any piece is called 'Object' in Ruby.
irb(main):001:0> "Hello World"
=> "Hello World"
irb(main):002:0> 7
=> 7
Interactive Ruby is a calculator on its own. Simple mathematical calculations can be performed very easily on irb terminal, that include basic arithmetic operations(Addition, Subtraction, Multiplication, Division), exponent and remainder. Division is done based on the input type: Integer or Float.
irb(main):003:0> 4+5
=> 9
irb(main):004:0> 6-3
=> 3
irb(main):005:0> 3*2
=> 6
irb(main):006:0> 5/3
=> 1
irb(main):007:0> 5.0/3.0
=> 1.6666666666666667
irb(main):008:0> 2**3
=> 8
irb(main):009:0> 7%4
=> 3
String operation is also very easy to perform in Ruby. There are many methods for strings manipulation.
irb(main):010:0> "Hello World".length
=> 11
irb(main):011:0> "Hello "+"World"
=> "Hello World"
irb(main):012:0> "Hello ".concat("World")
=> "Hello World"
irb(main):013:0> "hello".capitalize
=> "Hello"
irb(main):014:0> "hello".reverse
=> "olleh"
irb(main):015:0> "hello".next
=> "hellp"
irb(main):016:0> "hello".upcase
=> "HELLO"
irb(main):017:0> "HELLO".downcase
=> "hello"
irb(main):018:0> "hElLo".swapcase
=> "HeLlO"
Variable can be used in Ruby right away without declaration. You just need to set the value of a variable and start using it. Variable name must begin with lowercase letter. Constants are the variables with first letter in uppercase.
irb(main):019:0> city = "Delhi"
=> "Delhi"
irb(main):020:0> age = 25
=> 25
Print and Puts command are used to print the value in Ruby. The print command just prints the value to the screen whereas puts adds a new (blank) line after value to be printed. Here, nil is returned by the commands which is Ruby’s absolutely-positively-nothing value.
irb(main):021:0> print "Hello"
Hello=> nil
irb(main):022:0> puts "Hello"
Hello
=> nil
These basics can be practiced in Interactive Ruby with ease which will give you the basic idea of how Ruby commands works. In next article, I will cover the Control Flow in Ruby.

Thursday, October 9, 2014

Ruby Installation


Ruby is a cross platform, interpreted and object-oriented language. You need to install Ruby, on any platform on which you wish, to be able to develop or run the existing Ruby programs. It can be easily installed on Windows, Mac OS and Linux/Unix.

Installing the Ruby is very simple and I would guide you through installation on Windows as a platform by using the Ruby Installer for Windows. It gives you everything you need to set up a full Ruby development environment on Windows. If you are having Mac or Linux platform or if you are interested to know about other ways to download the Ruby on your machine, I would suggest a read on Ruby Installation on its official site: Installation Link.

1. Download and Install:


     Download the latest version of Ruby 2.1.3 or you may also download the currently most stable Ruby 1.9.3. Once it is downloaded, double-click the installer to start the installation. Select language and agree to the terms; and then check the boxes as shown in the figure:


Select the check box to set the System Environment Variable Path to the bin folder of Ruby and associate .rb and .rbw files.
Click Install.

2. Ruby on Start Menu:


     Ruby is installed on your machine and can be seen in the Start Menu. It has different entries: Interactive Ruby, which is IRB in a standard command line window; RubyGems Documentation Server, which starts the web server and run the gem command to install the gems on your server; Start Command Prompt with Ruby, which start ruby in command prompt if environment variable is not set for ruby yet; and Documentation, which contains the Ruby API documentation.

3. Install an Editor:


     Install any editor to write the Ruby programs as Ruby installer does not come with an editor or IDE. You can write in Notepad, but it is boring and dull to write in there. So, editor that can be considered includes Notepad++, Programmers' notepad, Sublime text or Scite among others.

This is what all needs to be done to install Ruby. You can start learning Ruby from tutorials online and create your own programs.

Wednesday, September 24, 2014

Ruby: A good pick for a tester to start Programming


Never actually learned programming. Don't have an idea how programming language can be mastered. Ever thought of starting programming and then dropped it. Afraid of syntax. Well, having yourself in the middle of these conditions, you may someday want to decide to start programming. You say, why not ! lets give it shot !!!

It's not that easy to learn a language to start programming in. But, then it's not that tough too. You just need an urge and patience and a hope. An urge to learn, the patience to keep going when code fails and a hope that one day you will have the confidence of writing lines of codes without compiling till the program is written well-off. So, starting to learn Ruby as your first programming is a good choice for every newbie, in general and testers, in particular(this blog is mostly dedicated to tester who want to learn programming and eventually move into Automation). Once, you learn one language it is easier to grasp other similar programming languages.

Ruby is a dynamic, reflective, object-oriented, general-purpose programming language. It was designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan. This is the description of Ruby copied from Wikipedia. It surely is dynamic programming language that means it is interpreted at runtime rather than compiled before execution, and can be used for writing software in a wide variety of application domains. It is higher level language and very easy to learn. 

Every language has a learning curve. After having the basic idea of the programming like data structures, objects, etc, the significant role is played by the syntax. It is the syntax that make the learning fast or slow. Once, you get the hold of it, things goes pretty smooth. People who have experience of programming in one language have the confidence to learn other languages for the very same reason because more or less syntax of different languages are similar. Ruby has far simple the syntax as compared to C++ or Java.

Though every language has its pros and cons. But, if you are choosing your first language you can definitely see Ruby as the best option and start creating cool websites in days to come. And, then you can always learn new languages and framework to enhance your skills and may switch to Java as well to broaden the purview.

Stay connected for more blog on the Ruby. I will be covering selenium also and will finally fuse the both to create Selenium automation framework in Ruby.