Archive for the 'Ruby Howto' Category

Using temporary files in Ruby - Tempfile.new

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 [...]

Using Ruby’s http library - download and process web pages - I

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 [...]

Advanced Ruby - Dynamic code execution

One of the advanced features of Ruby, which is behind the success of rails is the dynamic code execution. Code fragments can be executed using eval method. This is very similar to JavaScript eval function.
following is an example,

eval “x =10; puts x;” # print 10 using dynamic code execution

eval executes the code in the current [...]

Interacting with Ruby’s runtime environment

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.

class EnvSample

# how to detect operating system platform
# check [...]