For certain programming solutions, you might need a temporary file. Different operating systems store temporary files in different locations. Also you don’t want to explicitly name the file since that is irrelevant in the program. How do you ensure that there are no filename conflicts? The solution for all these is to use library for […]
Archive for the 'Code Snippets' Category
Ruby has excellent networking support. Ruby has low level networking features such as sockets and tcp/ip protocols. It also has a high level API for handling protocols such as http and ftp. In this post we will look the Ruby http library. We also look at how this library can be used to download and […]
In this post I will look at various ways of interacting with a Ruby program’s runtime environment. Following sample program has methods to identify the operating system platform, environment variables in the OS and finding out the command line parameters.
Ruby is a relatively young language. One of the advantages with this is that Ruby has libraries for common programming needs. In this post, I will show you how easy it is to process CSV files in Ruby. A CSV file contains comma separated values and is an easy way to store information in text […]
The following program gives good illustration of string functions, regular expressions and blocks. This is a solution to the Reverse Polish Notation generator problem explained at http://www.spoj.pl/problems/ONP/. Given an algebraic expression with brackets, this program will output the corresponding RPN form. For example, (a+(b+c)) becomes abc++. A good exercise will be to extend this program […]
One of the best ways to start learning Ruby is to try out simple programming problems. Let us see how we can generate fibonacci series using Ruby, This is a verbose an example. You could achieve the same in a single line!