[#21872] Let's work on Windows support — Dave Thomas <Dave@...>

98 messages 2001/10/01
[#21957] Re: Let's work on Windows support — "Benoit Cerrina" <benoit.cerrina@...> 2001/10/02

> I seem to remember that versions of Python compiled with MinGW can't have

[#21960] Re: Let's work on Windows support — "Furio R. Filoseta (tlf.)" <furifilo901@...> 2001/10/02

I am just a developer, not a Guru, but it seems to me that the .NET way

[#21963] Re: Let's work on Windows support — Albert Wagner <alwagner@...> 2001/10/03

On Tuesday 02 October 2001 18:20, you wrote:

[#21965] Re: Let's work on Windows support — "Furio R. Filoseta (tlf.)" <furifilo901@...> 2001/10/03

Come on, for Ruby developers in Windows environment. You may as well be

[#21969] Re: Let's work on Windows support — David Alan Black <dblack@...> 2001/10/03

Hello --

[#22153] Re: Let's work on Windows support — "Conrad Schneiker" <schneiker@...> 2001/10/06

Hi,

[#22154] Re: Let's work on Windows support — David Alan Black <dblack@...> 2001/10/06

Hello --

[#22167] Re: Let's work on Windows support — Mathieu Bouchard <matju@...> 2001/10/06

On Sat, 6 Oct 2001, David Alan Black wrote:

[#22183] Re: Let's work on Windows support — "Furio R. Filoseta (tlf.)" <furifilo901@...> 2001/10/07

Who cares if they ditch the standard ? They will still have to be self

[#21959] Flogging a live Window — Eli Green <eli.green@...>

Ok, I wanted to get away from the theory and conjecture thread of the

23 messages 2001/10/02

[#22003] Marshal won't dump a Proc — "HarryO" <harryo@...>

I would really like to be able to dump a block of code via Marshal#dump,

17 messages 2001/10/03

[#22107] The Windows question still remains... — Robert Hicks <bobhicks@...>

VC++

17 messages 2001/10/04
[#22111] Re: The Windows question still remains... — Robert Hicks <bobhicks@...> 2001/10/05

Shan-leung Maverick WOO wrote:

[#22166] dRuby, Linux and ports — ptkwt@...1.aracnet.com (Phil Tomson)

13 messages 2001/10/06

[#22219] - BRITNEY SPEARS NAKED----WOW!!!!!! — -.597i1468vn4848nc3958vn32858238@...

BRITNEY SPEARS COCK SUCKING VIDEO---EXCLUSIVE!!!

19 messages 2001/10/08

[#22257] [Newbie] Switching from Perl : suffling — Damien WYART <damien.wyart@...>

Dear All,

13 messages 2001/10/08

[#22299] Re: Less than 4 days now... — Andrew Hunt <andy@...>

>> Is everyone ready for the

27 messages 2001/10/09
[#22300] Re: Less than 4 days now... — Robert Feldt <feldt@...> 2001/10/09

Hi,

[#22310] Re: Less than 4 days now... — Dave Thomas <Dave@...> 2001/10/09

"Hal E. Fulton" <hal9000@hypermetrics.com> writes:

[#22316] Re: Less than 4 days now... — Todd Gillespie <toddg@...> 2001/10/09

On Tue, 9 Oct 2001, Dave Thomas wrote:

[#22320] Re: Less than 4 days now... — Dave Thomas <Dave@...> 2001/10/09

Todd Gillespie <toddg@mail.ma.utexas.edu> writes:

[#22347] Re: Less than 4 days now... — Robert Feldt <feldt@...> 2001/10/09

On Wed, 10 Oct 2001, Dave Thomas wrote:

[#22325] blocks with min and max — Mark Slagell <ms@...>

I don't know if this has been raised before, but I'd like to be able to

17 messages 2001/10/09

[#22405] list comprehensions alike Python ??? — markus jais <info@...>

hello

20 messages 2001/10/10
[#22407] Re: list comprehensions alike Python ??? — Robert Feldt <feldt@...> 2001/10/10

On Thu, 11 Oct 2001, markus jais wrote:

[#22411] Re: list comprehensions alike Python ??? — Paul Prescod <paul@...> 2001/10/11

Robert Feldt wrote:

[#22432] OSSL opinion — Michal Rokos <rokosm@...>

Hello!

16 messages 2001/10/11

[#22465] Learn Ruby/Tk or Ruby/GTK? && Problems with these. — "dAHen" <steensland@...>

Hi!

45 messages 2001/10/12
[#22472] Re: Learn Ruby/Tk or Ruby/GTK? && Problems with these. — "dAHen" <steensland@...> 2001/10/12

ts> No, you just need to have the header files and libraries for tcl/tk and

[#22520] Re: Learn Ruby/Tk or Ruby/GTK? — Kevin Smith <kevinbsmith@...> 2001/10/14

--- dAHen <steensland@hotmail.com> wrote:

[#22613] Re: Learn Ruby/Tk or Ruby/GTK? — stesch@... (Stefan Scholl) 2001/10/16

On 2001-10-15 19:58:29Z, Christopher Sawtell <csawtell@paradise.net.nz> wrote:

[#22625] Re: Learn Ruby/Tk or Ruby/GTK? — Kevin Smith <kevinbsmith@...> 2001/10/16

--- Stefan Scholl <stesch@no-spoon.de> wrote:

[#22632] Re: Learn Ruby/Tk or Ruby/GTK? — "Mark Hahn" <mchahn@...> 2001/10/16

[#22645] What about FLTK? — "Mark Hahn" <mchahn@...> 2001/10/16

[#22652] Re: What about FLTK? — Kevin Smith <kevinbsmith@...> 2001/10/17

--- Mark Hahn <mchahn@facelink.com> wrote:

[#22656] Re: What about FLTK? — "Mark Hahn" <mchahn@...> 2001/10/17

That's good to know. It makes me more comfortable to proceed assuming FLTK.

[#22494] extracting from delimited text files — Albert Wagner <alwagner@...>

What is the simplist way to extract fields from standard quoted, comma

23 messages 2001/10/13
[#22496] Re: extracting from delimited text files — Robert Linder <robert_linder_2000@...> 2001/10/13

Check out http://ruby.yi.org/raa/en/all.html

[#22502] Open-ended ranges — Sean Russell <ser@...>

Before I post an RCR on this, I'd like to solicit information from the more

11 messages 2001/10/14
[#22503] Re: Open-ended ranges — Robert Feldt <feldt@...> 2001/10/14

On Sun, 14 Oct 2001, Sean Russell wrote:

[#22766] ANN: RuEdit - introspective Ruby editor — phlip_cpp@... (Phlip)

Here's the README file from http://sourceforge.net/projects/ruedit :

31 messages 2001/10/19

[#22769] How to Convert String to Regex to Perform Exact Match — William Djaja Tjokroaminata <billtj@...>

Hi,

10 messages 2001/10/19

[#22867] RE: I need some help!! — Mikkel Bruun <mikkel.bruun@...>

uhhmm...

14 messages 2001/10/21
[#22883] Re: I need some help!! — Tobias Reif <tobiasreif@...> 2001/10/21

Mikkel Bruun wrote:

[#22886] Re: I need some help!! — "Avdi B. Grimm" <avdi@...> 2001/10/21

On Sun, 2001-10-21 at 15:26, Tobias Reif wrote:

[#22871] Preaching Ruby to the masses. How? — Kent Dahl <kentda@...>

Hi.

17 messages 2001/10/21

[#23063] Bruce Eckel's opinion of Ruby — "Rich Kilmer" <rich@...>

Ouch!

178 messages 2001/10/23
[#23076] Re: Bruce Eckel's opinion of Ruby — Eric Lee Green <eric@...> 2001/10/23

On Tuesday 23 October 2001 11:20, you wrote:

[#23084] Re: Bruce Eckel's opinion of Ruby — Michael Neumann <neumann@...> 2001/10/23

Eric Lee Green wrote:

[#23087] Re: Bruce Eckel's opinion of Ruby — Eric Lee Green <eric@...> 2001/10/23

On Tuesday 23 October 2001 13:25, you wrote:

[#23088] Re: Bruce Eckel's opinion of Ruby — Robert Feldt <feldt@...> 2001/10/23

On Wed, 24 Oct 2001, Eric Lee Green wrote:

[#23096] Re: Bruce Eckel's opinion of Ruby — "Rich Kilmer" <rich@...> 2001/10/23

[#23099] Re: Bruce Eckel's opinion of Ruby — Robert Feldt <feldt@...> 2001/10/23

On Wed, 24 Oct 2001, Rich Kilmer wrote:

[#23090] Re: Bruce Eckel's opinion of Ruby — Paul Brannan <pbrannan@...> 2001/10/23

On Wed, 24 Oct 2001, Michael Neumann wrote:

[#23085] Re: Bruce Eckel's opinion of Ruby — Robert Feldt <feldt@...> 2001/10/23

Hi Eric and thanks for your detailed comments,

[#23119] Re: Bruce Eckel's opinion of Ruby — Sean Russell <ser@...> 2001/10/23

Eric Lee Green wrote:

[#23141] Re: Bruce Eckel's opinion of Ruby — Emiliano <emile@...> 2001/10/24

Sean Russell wrote:

[#23219] Re: Bruce Eckel's opinion of Ruby — Sean Russell <ser@...> 2001/10/24

Emiliano wrote:

[#23221] Re: Bruce Eckel's opinion of Ruby — Emiliano <emile@...> 2001/10/24

Sean Russell wrote:

[#23259] Re: Bruce Eckel's opinion of Ruby — Sean Russell <ser@...> 2001/10/25

Emiliano wrote:

[#23264] Re: Bruce Eckel's opinion of Ruby — Emiliano <emile@...> 2001/10/25

Sean Russell wrote:

[#23439] Re: Issues with white space [was Re: Bruce Eckel's opinion of Ruby] — Sean Russell <ser@...> 2001/10/26

Raja S. wrote:

[#23447] Re: Issues with white space [was Re: Bruce Eckel's opinion of Ruby] — ts <decoux@...> 2001/10/26

>>>>> "S" == Sean Russell <ser@efn.org> writes:

[#23108] Re: Bruce Eckel's opinion of Ruby — Sean Russell <ser@...> 2001/10/23

Emiliano wrote:

[#23214] () vs (...) in header files — Paul Brannan <pbrannan@...>

There is a serious problem with including ruby.h and intern.h in C++

14 messages 2001/10/24
[#23283] Re: () vs (...) in header files — ts <decoux@...> 2001/10/25

>>>>> "P" == Paul Brannan <pbrannan@atdesk.com> writes:

[#23248] [ANN] RubyInRubyParser 0.1-pre-alpha — markus liedl <markus.lado@...>

53 messages 2001/10/25
[#23323] Re: [ANN] RubyInRubyParser 0.1-pre-alpha — ptkwt@...1.aracnet.com (Phil Tomson) 2001/10/25

In article <5.1.0.14.0.20011025083950.00bc30b0@mercury.sabren.com>,

[#23336] Re: [ANN] RubyInRubyParser 0.1-pre-alpha — Jimmy Thrasher <jjthrash@...> 2001/10/25

At 02:54 AM 10/26/2001 +0900, you wrote:

[#23350] Re: GUI / was [ANN] RubyInRubyParser 0.1-pre-alpha — markus liedl <markus.lado@...> 2001/10/25

> having a native window with a canvas which Ruby draws on using the BitBlt

[#23355] Re: GUI / was [ANN] RubyInRubyParser 0.1-pre-alpha — "Rich Kilmer" <rich@...> 2001/10/25

I wrote a sophisticated lightweight component framework on Java (before Swing) that was very fast. Of course, writing it in a "higher level" language adds overhead, but not as much overhead as bad design ;-) If you could have low-level primitives written natively and layer higher level constructs with Ruby, I think you could build a very responsive UI.

[#23369] Re: GUI / was [ANN] RubyInRubyParser 0.1-pre-alpha — Eli Green <eli.green@...> 2001/10/25

I never understood why Swing was so slow. I do know, however, that Swing is

[#23371] Re: GUI / was [ANN] RubyInRubyParser 0.1-pre-alpha — Avi Bryant <avi@...4.com> 2001/10/25

On Fri, 26 Oct 2001, Eli Green wrote:

[#23261] Ruby macros — Leo <lraz@...>

Hi Ruby experts,

19 messages 2001/10/25

[#23318] class Foo does not call Class.new? — Brian Marick <marick@...>

It seems that this:

25 messages 2001/10/25
[#23358] Re: class Foo does not call Class.new? — matz@... (Yukihiro Matsumoto) 2001/10/25

Hi,

[#23360] Re: class Foo does not call Class.new? — David Alan Black <dblack@...> 2001/10/25

Hello --

[#23395] Re: class Foo does not call Class.new? — matz@... (Yukihiro Matsumoto) 2001/10/26

Hi,

[#23680] Re: ref. constructors and new (was: Re: class Foo does not call Class.new?) — David Alan Black <dblack@...> 2001/10/28

Hello --

[#23396] Ruby and Python: a fuzzy question — Dave Thomas <Dave@...>

37 messages 2001/10/26
[#23406] Re: Ruby and Python: a fuzzy question — "F. GEIGER" <fgeiger@...> 2001/10/26

Python and Ruby both are write/read scripting languages, which are in one or

[#23544] Fast reply needed: class var trouble — Robert Feldt <feldt@...>

Ok its getting late over here in sweden and I'm tired. Can someone please

21 messages 2001/10/26
[#23548] RE: Fast reply needed: class var trouble — "Rich Kilmer" <rich@...> 2001/10/26

[#23555] Re: Fast reply needed: class var trouble — Robert Feldt <feldt@...> 2001/10/26

On Sat, 27 Oct 2001, Rich Kilmer wrote:

[#23557] Re: Fast reply needed: class var trouble — "Rich Kilmer" <rich@...> 2001/10/26

because you defined:

[#23558] Re: Fast reply needed: class var trouble — Robert Feldt <feldt@...> 2001/10/26

On Sat, 27 Oct 2001, Rich Kilmer wrote:

[#23561] Re: Fast reply needed: class var trouble — "Ralph Mason" <ralph.mason@...> 2001/10/26

I would rather have the option to require declaration of all variables.

[#23619] sleeping, calling methods inside class defs — Tobias Reif <tobiasreif@...>

ruby 1.6.3 (2001-03-19) [i386-cygwin]

15 messages 2001/10/27
[#23621] Re: sleeping, calling methods inside class defs — David Alan Black <dblack@...> 2001/10/27

Hello --

[#23658] How to get a String to interpolate itself? — ptkwt@...1.aracnet.com (Phil Tomson)

11 messages 2001/10/28

[#23668] Ruby's use of cygwin and commercial use! — Sunil Hadap <hadap@...>

Hi,

23 messages 2001/10/28
[#23865] Re: Ruby's use of cygwin and commercial use! — "Benoit Cerrina" <benoit.cerrina@...> 2001/10/30

[#23866] Overiding a method in another module — "Mark Hahn" <mchahn@...> 2001/10/30

I want to write a module that overrides a method in another module. I have

[#23885] RE: Overiding a method in another module — "Mark Hahn" <mchahn@...> 2001/10/31

[#23893] Re: Overiding a method in another module — David Alan Black <dblack@...> 2001/10/31

Hello --

[#23713] Some inspirations from REBOL — Robert Feldt <feldt@...>

Hi,

42 messages 2001/10/29
[#23735] RE: Some inspirations from REBOL — "Ryan Leavengood" <mrcode@...> 2001/10/29

> However, it's got some nice properties that my friend has been

[#23738] Re: Some inspirations from REBOL — Michael Neumann <neumann@...> 2001/10/29

Ryan Leavengood wrote:

[#23764] Re: Some inspirations from REBOL — Robert Feldt <feldt@...> 2001/10/29

On Tue, 30 Oct 2001, Ryan Leavengood wrote:

[#23769] RubyGems Status (was: Re: Some inspirations from REBOL) — "Ryan Leavengood" <mrcode@...> 2001/10/29

> Any news on RubyGems? I'm not pushing you just wanting a status report

[#23773] Re: RubyGems Status (was: Re: Some inspirations from REBOL) — Robert Feldt <feldt@...> 2001/10/29

On Tue, 30 Oct 2001, Ryan Leavengood wrote:

[#23779] Re: RubyGems Status (was: Re: Some inspirations from REBOL) — "Ryan Leavengood" <mrcode@...> 2001/10/29

> Release to CVS as quickly as possible!

[#23783] Re: RubyGems Status (was: Re: Some inspirations from REBOL) — Robert Feldt <feldt@...> 2001/10/29

On Tue, 30 Oct 2001, Ryan Leavengood wrote:

[#23786] Re: RubyGems Status (was: Re: Some inspirations from REBOL) — Neil Conway <nconway@...> 2001/10/30

On Mon, 2001-10-29 at 18:56, Robert Feldt wrote:

[#23793] Re: RubyGems Status (was: Re: Someinspirations from REBOL) — "Rich Kilmer" <rich@...> 2001/10/30

OK...here's an idea for making a Gem a Ruby executable file...

[#23768] RCR: Fun with attribute shortcuts solves RCR #3 and more — Gunnar Andersson <dff180@...>

Hi everyone, remember this?

19 messages 2001/10/29

[#23868] Re: Ruby's use of cygwin and commercial use! — Andrew Hunt <andy@...>

Benoit says:

14 messages 2001/10/30

[#23876] New RubyGarden Poll: Windows support — Dave Thomas <Dave@...>

28 messages 2001/10/30
[#23891] Re: New RubyGarden Poll: Windows support — "Nat Pryce" <nat.pryce@...13media.com> 2001/10/31

Please! Don't vote for what you think will win. Vote for what you actually

[#23896] Re: New RubyGarden Poll: Windows support — "Curt Hibbs" <curt@...> 2001/10/31

What would MinGW buy us over straight MSVC? Since MinGW ultimately uses the

[#23915] Re: New RubyGarden Poll: Windows support — ptkwt@...1.aracnet.com (Phil Tomson) 2001/10/31

In article <NCBBJBPADKGIOFLDNEALMEHKFFAA.curt@hibbs.com>,

[#23882] RubyGems Discussion — "Ryan Leavengood" <RyanL@...>

Wow, there has been a lot of discussion related to RubyGems over the

19 messages 2001/10/30

[#23904] Test::Unit = Lapidary + RubyUnit — "Nathaniel Talbott" <ntalbott@...>

I've been in discussions with Masaki Suketa and Ken McKinlay about the

12 messages 2001/10/31

[#23959] Creating charts from Ruby — Robert Feldt <feldt@...>

Hi,

16 messages 2001/10/31

[ruby-talk:22530] Re: Open-ended ranges

From: Robert Feldt <feldt@...>
Date: 2001-10-14 22:27:39 UTC
List: ruby-talk #22530
On Mon, 15 Oct 2001, Sean Russell wrote:

> Hmmm.  Well, Ranges are lazily evaluated; they are not converted internally 
> to arrays, and I don't see any reason why they open-ended ranges wouldn't 
> be possible -- EXCEPT for the to_a issue, which is indeed a stumper.  But, 
> consider, for a moment, a number class tha wraps Integer, which provides 
> constants INFINITY and NEGATIVE_INFINITY, and which supports succ and <=> 
> such that x <=> MyInt::INFINITY is always -1.  You could easily make a 
> range of this, although to_a would hang.
> 
Ok, I agree that its possible (most things are! :-)) but then someone will
do (1..).each and keep on waiting (granted there are always many things
you can do to screw up) 'til mem runs out... ;-)
 
> >> PS.  I was following the "versioned require" discussion for a while, but
> >> it
> ....
> > Many people seem to think that something along those lines would be a
> > good thing. There is not yet a consensus on which semantics to use and how
> > to implement. Maybe the RAA.succ/RubyGems discussion/solution can revive
> > this discussion again?
> 
> I've seen at least one extension which enabled this, but this is the sort 
> of thing that is almost useless unless it is ubiquitous.  IE, the NEED for 
> this is usually in moving software around from one machine to another, so 
> if it isn't part of core Ruby, its usefullness is extremely limited.
> 
I agree and I think Ryan Leavengoods upcoming RubyGems and the outcome
from the Raa.succ DesignFest at RubyConf might make starting points for a
standard way. So something is probably coming along this year...

However, there is one way to do this that would work with only minimal
support from the core/std Ruby: the gems/archives are simply
Marshal.dump'ed objects with a simple Ruby loader. This way people can
introduce custom gems as long as they respond to some standardized
messages. I actually did a tracer bullet along those lines. The gems it
produces has three parts:

1. Minimal Ruby program that unpacks string in 2 and eval's it and then
   loads object in 3 and sends it ARGV
2. Possibly empty string with source code that defines the object in 3 (or
the differences between the object in 3 and a std Gem class but there is a
trade off here)
3. Marshal.dump'ed Gem object that can list, unpack, install itself etc.

Code is below for interested souls... Sorry for the length. (Note that it
seems kind of strange to add the source code in a string (2) that is then
eval'ed instead of including it in the loader directly; my thought with
this was that it might be compressed...)

A potential quirk with this scheme is if the Marshal format changes
between Ruby versions. I don't think it has changed since 1.6 though, but
I'm not sure...

Regards,

Robert

gem.rb
------
require 'ftools'

def loader_source_code(src_code_length, length)
  if src_code_length > 0
    eval_src = <<EOS
  f.seek(-#{length+src_code_length}, IO::SEEK_END)
  eval(f.read(src_code_length))
EOS
  else
    eval_src = ""
  end
  str  = <<EOS
require 'gem'
File.open(__FILE__) do |f|
#{eval_src}  f.seek(-#{length}, IO::SEEK_END)
  Gem.load(f.read(#{length})).call(ARGV)
end
__END__
EOS
  str
end

class Gem
  # Most of the attributes modeled after Debian Package system, see
  # http://www.debian.org/doc/FAQ/ch-pkg_basics.html
  #
  attr_accessor :name, :version, :category, :ruby_dependency, :maintainer
  attr_accessor :maintainer_email, :architecture, :dependencies
  attr_accessor :description

  # Possible additions:
  #   Status: planning/pre-alpha/alpha/beta/stable/mature
  #   Type: pure-ruby/C 

  def initialize(name, aHash = {})
    @name, @archive = name, FileArchive.new
    set_from_hash(aHash)
  end

  def set_from_hash(aHash)
    @version = aHash[:version] || "0.1"
    @category = aHash[:category] || ""
    @ruby_dependency = 
      aHash[:ruby_dependency] || aHash[:ruby] || Dependency.new("ruby",
"1.6")
    @maintainer = aHash[:maintainer] || "unknown"
    @maintainer_email = aHash[:maintainer_email] || "unknown"
    @architecture = aHash[:architecture] || aHash[:arch] || "any"
    @dependencies = aHash[:dependencies] || aHash[:deps] || []
    @description = aHash[:description] || aHash[:desc] || ""
  end

  def inspect
    "Name:".ljust(20)            + name                    + "\n" +
    "Version:".ljust(20)         + version                 + "\n" +
    "Category:".ljust(20)        + category                 + "\n" +
    "Ruby dependency:".ljust(20) + ruby_dependency.inspect + "\n" +
    "Maintainer:".ljust(20)      + maintainer +
" <#{maintainer_email}>\n" +
    "Architecture:".ljust(20)    + architecture            + "\n" +
    "Dependencies:".ljust(20)    + dependencies.inspect    + "\n" +
    "Description:\n" +
      format_description(description)
  end

  # Subclasses should add their source code here so that they can be
  # unpacked even if the Gem user does not have pre-installed their source 
  # code.
  def non_standard_ruby_source_code
    "" + @archive.non_standard_ruby_source_code
  end

  def add_file(filename)
    @archive.add_file(filename)
  end

  def marshal
    marshaled_gem = Marshal.dump(self)
    non_std_src = non_standard_ruby_source_code
    loader_source_code(non_std_src.length, marshaled_gem.length) + 
      non_std_src + marshaled_gem
  end

  def Gem.load(str)
    Marshal.load(str)
  end

  def usage
    usage_message(name, version)
  end

  def install
    unpack
    puts "Installing..."
    install_files
  end

  def unpack
    puts "Unpacking..."
    unpack_files
  end

  def list
    puts "Files in gem:"
    if @archive.num_files > 0
      @archive.each {|file, size, str| puts " #{file} (#{size})"}
    else
      puts " None."
    end
  end

  def unpack_files
    @archive.each do |filename, size, str|
      puts "  #{filename}"
      File.makedirs(File.dirname(filename))
      File.open(filename, "w") {|f| f.write str}
    end
  end

  def install_files
    raise NotImplementedError, "Install not yet implemented!"
  end

  def clean
    files.each do |filename, len, str|
      File.delete(filename)
    end
    # Also delete subdirs we have created? Maybe not...
  end

  def call(argv)
    argv.push nil if argv.length == 0
    while argv.length > 0
      case argv[0]
      when "--install", "-i"
	std_command(:install)
      when "--unpack", "-u"
	std_command(:unpack)
      when "--list", "-l"
	std_command(:list)
      when "--clean", "-c"
	std_command(:clean)
      else
	print "Invalid option!\n\n" if argv[0]
	puts usage
	puts "Gem info"
	puts "--------"
	puts inspect
	exit
      end
      argv.shift
    end
  end

  private

  def std_command(command, *args)
    puts inspect
    self.send(command, *args)
  end

  def usage_message(name, version)
    str = <<EOS
Gem: #{name} (#{version})
  -i, --install     Unpack and install files in gem
  -u, --unpack      Unpack files in gem
  -l, --list        List files in gem
  -c, --clean       Delete the files unpacked from the gem
EOS
    str
  end

  def indent(aString, steps = 1)
    spaces = " " * steps
    spaces + aString.split("\n").join(spaces + "\n")
  end

  def format_description(aString)
    indent(aString)
  end
end

# Debian has many different "dependencies" not only the must-have one
# I represent below. Maybe call them Relations and have subclasses for
# depends (must-have), recommends, suggests, conflicts, replaces,
provides?
class Dependency
  include Comparable

  attr_reader :name, :version

  def initialize(name, version = "0.0")
    @name, @version = name, version
  end

  def <=>(other)
    if name == other.name
      version <=> other.version
    else
      name <=> other.name
    end
  end

  def inspect_version
    version == "0.0" ? "" : " (#{version})"
  end

  def inspect
    "#{name}#{inspect_version}"
  end
end

def dep(*args)
  Dependency.new(*args)
end

class Stream
  def initialize
    @data = ""
  end

  def <<(aString)
    @data << aString
  end

  def length
    @data.length
  end

  def [](position, length)
    @data[position, length]
  end

  def delete_bytes(position, length)
    self[position, length] = ""
    self
  end

  # Subclasses should add their source code here so that their streams can
be
  # unpacked even if the Gem user does not have installed the stream
  def non_standard_ruby_source_code
    ""  # This stream is supposed to be included with Ruby so everyone has
it!
  end
end

class FileArchive
  attr_reader :info

  def initialize
    @info, @stream = Hash.new, Stream.new
  end

  def add_file(filename)
    File.open(filename, "r") do |f|
      delete_content(filename) if include?(filename)
      content = f.read
      info[filename] = [stream.length, content.length]
      stream << content
    end
  end

  def num_files
    @info.length
  end

  def each
    @info.each do |filename, (position, length)|
      yield(filename, length, @stream[position, length])
    end
  end

  def get_file(filename)
    stream[*info[filename]]
  end

  def include?(filename)
    info.include?(filename)
  end

  def non_standard_ruby_source_code
    # This archiver is supposed to be included with Ruby so everyone has
it!
    "" + stream.non_standard_ruby_source_code
  end

  private

  attr_reader :stream

  def delete_content(filename)
    position, length = info[filename]
    stream.delete_bytes(position, length)
    delete_info(filename, position, length)
  end

  def delete_info(filename, position, length)
    info.each do |name, (pos, len)|
      info[name] = [pos-length, len] if pos > position
    end
    info.delete(name)
  end
end

if __FILE__ == $0
  g = Gem.new("CryptoLib", 
	      :ruby => dep("ruby", "1.7.1"),
	      :maintainer => "Robert Feldt",
	      :maintainer_email => "feldt@ce.chalmers.se",
	      :category => "algorithms/cryptography",
	      :deps => [dep("zlib"), dep("optparse", "0.4")],
	      :desc => "Cryptography algorithms implemented in pure Ruby
(ie. *NO* C code).")
  puts g.inspect  

  ARGV[1..-1].each do |filename|
    g.add_file(filename)
  end

  if ARGV[0]
    File.open(ARGV[0] + ".gem", "w") {|f| f.write g.marshal}
  end
end


In This Thread