Posts tagged ‘ruby’

I have started a programming blog here.

Managed to compile and package Ruby 1.9.0-3 for Openmoko!!!

Download: ruby19-complete_190-3_armv4t

[Update]

Here’s the ruby package without dev and documentation (this would be smaller and more appropriate on the phone) - ruby19_190-3_armv4t

Creating a Ruby 1.9 sandbox

1. mkdir /home/user/ruby19 (example folder)
2. cd /home/user/ruby19
3. mkdir src
4. cd src
5. wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.0-1.tar.bz2
6. tar -jxvf ruby-1.9.0-1.tar.bz2
7. cd ruby-1.9.0-1
8. ./configure –prefix=/home/user/ruby19
9. make
10. make install

Now you can switch to this sandbox at any time by executing ‘export PATH=/home/user/ruby19/bin:$PATH’ in a shell.

Chipmunk Installation

Chipmunk is required for Rubygame 3

1. wget http://files.slembcke.net/chipmunk/release/ChipmunkLatest.tgz
2. tar -zxvf ChipmunkLatest.tgz
3. cd Chipmunk-4.0.2
4. cd ruby
5. export PATH=/home/user/ruby19/bin:$PATH (* switching to Ruby 1.9 sandbox)
6. ruby extconf.rb
7. make
8. make install

Rubygame 3 Installation

1. mkdir /home/user/rubygame (example path)
2. cd /home/user/rubygame
3. svn co https://rubygame.svn.sourceforge.net/svnroot/rubygame/trunk rubygame3
4. cd rubygame3/
5. export PATH=/home/user/ruby19/bin:$PATH (* switching to Ruby 1.9 sandbox)
6. cat Rakefile | sed s/PLATFORM/RUBY_PLATFORM/ > Rakefile.new;mv Rakefile.new Rakefile (* this replaces PLATFORM with RUBY_PLATFORM in the Rakefile)
7. CFLAGS=”-I/home/user/ruby19/include/ruby-1.9.0 -I/home/user/ruby19/include/ruby-1.9.0/i686-linux” rake install
8. cd ~/rubygame/rubygame3/samples/
9. ruby chimp.rb
10. Punch the monkey!! :-)

How easy would it be to build include graphs in ruby?

Here's my first attempt:

RUBY:
  1. $list_of_files = Hash.new
  2. $list_of_files.each {|node|
  3. node = Array.new
  4. }
  5. def store_includes(pathname)
  6. lines = IO.readlines(pathname)
  7. lines.each {|line|
  8. if line.include? "#include"
  9. include_file = line[line.index("#include")+"#include".size,line.size]
  10. fidx = 0
  11. sidx = 0
  12.  
  13. if include_file.include?("\"")
  14. fidx = include_file.index("\"") + 1
  15. sidx = include_file.index("\"",fidx+1) - 1
  16. end
  17.  
  18. if include_file.include?('<')
  19. fidx = include_file.index('<') + 1
  20. sidx = include_file.index('>') - 1
  21. end
  22.  
  23. include_file = include_file[fidx..sidx]
  24. $list_of_files[pathname].add(include_file)
  25. end
  26. }
  27. end
  28.  
  29. def iterate_files(pathname)
  30. list = [] #alternate way of initializing an array
  31. if pathname=="." or pathname==nil
  32. list = Dir["*"]
  33. else
  34. list = Dir[pathname + File::SEPERATOR + "*"]
  35. end
  36. list.each { |path|
  37. if File.filetype(path) == "directory"
  38. iterate_files(pathname)
  39. end
  40. if File.filetype(path) == "file"
  41. store_includes(path)
  42. end
  43. }
  44. end

Any comments?

Is there a more efficient way to extract the file extensions in ruby? I currently do the following.

RUBY:
  1. ext = File.basename(filepath).reverse.split('.')[0].reverse