PLanET ABhisEK
< September 2006 >
SuMoTuWeThFrSa
      1 2
3 4 5 6 7 8 9
10111213141516
17181920212223
24252627282930

Fri, 15 Sep 2006 16:28:00 IST

RUBY ROCKZ!!

Oh yes, I am getting more and more impressed with Ruby.

Ruby being an apparently *very* simple and aesthetically pleasing language, but internally it is very complex in its implementation along with quite a few awesome and very intelligent hacks.

People interested in giving ruby a shot should surely start with the following:
* About Ruby
* Ruby in 20 min

People interested in Ruby internals can take a look at "Ruby Hacking Guide".

Oh and before saying bye for the day, I would love to give away some fun.
A nice and *probably* usable ruby shell ;-)

#!/usr/bin/ruby
require 'readline'

class RShell

   def initialize()
      Signal.trap('INT') {
         puts "Enter exit/quit to exit shell"
      }
   end

   def unixcmd?(cmd = nil)
      return nil unless cmd

      paths = ENV["PATH"].split(':')
      paths.each do |p|
         file = "#{p}/#{cmd.split(' ',2)[0]}"
         return true if File.exists? file
      end

      false
   end

   def run

      loop do
         cmd = Readline::readline("rsh #{ENV['PWD']}> $ ", true)
         exit if cmd =~ /exit|quit/
         if unixcmd? cmd
            system(cmd)
         else
            begin
               eval cmd
            rescue
               puts "Command not found"
            end
         end
         
      end
      
   end

end

RShell.new.run

http://eos-india.net/abhisek/codez/misc/rsh.rb

posted at: 16:28 | path: / | permanent link to this entry

Made with PyBlosxom