[#309764] The Rubyist -- a semi-monthly magazine for Rubyists AVAILABLE NOW — "Jeremy McAnally" <jeremymcanally@...>

Hello all,

9 messages 2008/08/01

[#309802] Using array.select with grep — Milo Thurston <knirirr@...>

Using irb I set up the following arrays:

16 messages 2008/08/01

[#309821] About circular dependencies in RubyGems (the library). And about the order in $". — "Erik Veenstra" <erikveen@...>

Hi,

13 messages 2008/08/01

[#309824] Determining MAC address — "Glen Holcomb" <damnbigman@...>

What would be the best (clean, cross-platform) way of determining the MAC

12 messages 2008/08/01

[#309867] Capturing shell command output and success? — "Kyle Schmitt" <kyleaschmitt@...>

I know shell commands have beaten to death on this list, but searching

10 messages 2008/08/01

[#309878] Help finding this syntax error — Patrick Li <patrickli_2001@...>

<code>

14 messages 2008/08/01

[#309903] unit testing advice — Shadowfirebird <shadowfirebird@...>

Forgive me if this is a stupid question.

58 messages 2008/08/01
[#309905] Re: unit testing advice — "Gregory Brown" <gregory.t.brown@...> 2008/08/01

On Fri, Aug 1, 2008 at 5:31 PM, Shadowfirebird <shadowfirebird@gmail.com> wrote:

[#309907] Re: unit testing advice — Shadowfirebird <shadowfirebird@...> 2008/08/01

Many thanks. Clearly I'm going to have to go back to research mode on

[#309916] Re: unit testing advice — Phlip <phlip2005@...> 2008/08/02

Shadowfirebird wrote:

[#309947] Re: unit testing advice — "David A. Black" <dblack@...> 2008/08/02

Hi --

[#309948] Re: unit testing advice — Phlip <phlip2005@...> 2008/08/02

David A. Black wrote:

[#309949] Re: unit testing advice — "David A. Black" <dblack@...> 2008/08/02

Hi --

[#309960] Re: unit testing advice — Shadowfirebird <shadowfirebird@...> 2008/08/02

I certainly "get" the idea that it's better to write the tests first.

[#309966] Re: unit testing advice — "David A. Black" <dblack@...> 2008/08/02

Hi --

[#309979] Re: unit testing advice — James Britt <james.britt@...> 2008/08/02

David A. Black wrote:

[#309983] Re: unit testing advice — "David A. Black" <dblack@...> 2008/08/02

Hi --

[#310011] Re: unit testing advice — James Britt <james.britt@...> 2008/08/03

David A. Black wrote:

[#310018] Re: unit testing advice — "David A. Black" <dblack@...> 2008/08/03

Hi --

[#310050] RubyConf 2008 call for talk proposals — Richard Kilmer <rich@...>

Ruby Central is pleased to announce that we are accepting

11 messages 2008/08/04

[#310127] hash code reference - this only returns 'nil' please help me — Mmcolli00 Mom <mmc_collins@...>

Please tell me what I am doing wrong. i thought h[ErrFieldID] would work

12 messages 2008/08/04
[#310128] Re: hash code reference - this only returns 'nil' please help me — Sebastian Hungerecker <sepp2k@...> 2008/08/04

Mmcolli00 Mom wrote:

[#310131] Re: hash code reference - this only returns 'nil' please help me — Mmcolli00 Mom <mmc_collins@...> 2008/08/04

Sebastian Hungerecker wrote:

[#310154] Matrix class: How to set a single element ? — Marcio Braga <mbraga0001@...>

simple code:

11 messages 2008/08/05

[#310159] State of the Onion — "M. Edward (Ed) Borasky" <znmeb@...>

http://www.gcn.com/online/vol1_no1/46724-1.html

36 messages 2008/08/05
[#310179] Re: State of the Onion — "Michael T. Richter" <ttmrichter@...> 2008/08/05

On Tue, 2008-08-05 at 11:05 +0900, M. Edward (Ed) Borasky wrote:

[#310190] Re: State of the Onion — "Martin DeMello" <martindemello@...> 2008/08/05

On Mon, Aug 4, 2008 at 8:48 PM, Michael T. Richter <ttmrichter@gmail.com> wrote:

[#310217] perl and the culture of libraries — "Martin DeMello" <martindemello@...>

http://blog.jrock.us/articles/You%20are%20missing%20the%20point%20of%20Perl.pod

60 messages 2008/08/05
[#310219] Re: perl and the culture of libraries — "Peter Fitzgibbons" <peter.fitzgibbons@...> 2008/08/05

I'm on board.

[#310223] Re: perl and the culture of libraries — "Martin DeMello" <martindemello@...> 2008/08/05

On Tue, Aug 5, 2008 at 6:04 AM, Peter Fitzgibbons

[#310228] Re: perl and the culture of libraries — "Peter Fitzgibbons" <peter.fitzgibbons@...> 2008/08/05

Sounds like some changes to rubygems and it's toolset.

[#310232] Re: perl and the culture of libraries — "Martin DeMello" <martindemello@...> 2008/08/05

On Tue, Aug 5, 2008 at 6:31 AM, Peter Fitzgibbons

[#310237] Re: perl and the culture of libraries — "Peter Fitzgibbons" <peter.fitzgibbons@...> 2008/08/05

Isn't it true, though, that rubygems are the defacto distribution model for

[#310240] Re: perl and the culture of libraries — "Martin DeMello" <martindemello@...> 2008/08/05

On Tue, Aug 5, 2008 at 7:05 AM, Peter Fitzgibbons

[#310249] Re: perl and the culture of libraries — Shadowfirebird <shadowfirebird@...> 2008/08/05

I don't wish to be critical (I really don't! That's not just a way of

[#310312] Re: perl and the culture of libraries — David Masover <ninja@...> 2008/08/06

On Tuesday 05 August 2008 07:56:22 Martin DeMello wrote:

[#310339] Re: perl and the culture of libraries — Shadowfirebird <shadowfirebird@...> 2008/08/06

I've seen some things posted in this thread (overnight for me) that I

[#310295] State of Ruby 1.8.6? — Jeff <cohen.jeff@...>

Can anyone provide an update to the state of Ruby 1.8.6?

19 messages 2008/08/05
[#310305] Re: State of Ruby 1.8.6? — Alex Fenton <alex@...> 2008/08/06

Jeff wrote:

[#310314] is there a way to AutoParse a string to another type - e.g. if a Date format then date, else if integer than Integer etc ????? — "Greg Hauptmann" <greg.hauptmann.ruby@...>

Hi,

7 messages 2008/08/06

[#310358] Threaded IO trouble — "Michal Suchanek" <hramrach@...>

Hello

13 messages 2008/08/06

[#310393] An introduction, in about 50 lines of Ruby. — Alexei Broner <lahgyk@...>

Hi, I'm Lex. I've been Rubying for a few months now and can't get

47 messages 2008/08/06
[#310582] Re: An introduction, in about 50 lines of Ruby. — Alexei Broner <lahgyk@...> 2008/08/08

You guys are no fun. I didn't even get "that's not really recursive,

[#310584] Re: An introduction, in about 50 lines of Ruby. — Yukihiro Matsumoto <matz@...> 2008/08/08

Hi,

[#310591] Re: An introduction, in about 50 lines of Ruby. — Trans <transfire@...> 2008/08/08

[#310639] Re: An introduction, in about 50 lines of Ruby. — James Britt <james.britt@...> 2008/08/08

Trans wrote:

[#310731] Re: An introduction, in about 50 lines of Ruby. — Trans <transfire@...> 2008/08/10

[#310740] Re: An introduction, in about 50 lines of Ruby. — James Britt <james.britt@...> 2008/08/10

Trans wrote:

[#310745] Re: An introduction, in about 50 lines of Ruby. — Trans <transfire@...> 2008/08/10

[#310413] Need help detecting overlapping ranges — Bryan Richardson <btrichardson@...>

Hello all,

18 messages 2008/08/06
[#310429] Re: Need help detecting overlapping ranges — "Martin DeMello" <martindemello@...> 2008/08/06

On Wed, Aug 6, 2008 at 11:48 AM, Bryan Richardson

[#310518] Most compact command for associate array 'totalling'? — John Pritchard-williams <monojohnny@...>

Ok - in 'awk' you can do this: (Where 'array' is empty initially)

10 messages 2008/08/07

[#310531] Ruby 1.8.7-p71 / 1.8.6-p286 released (Security Fix) — Urabe Shyouhei <shyouhei@...>

At last.

13 messages 2008/08/08

[#310540] Ruby IDE — "Mayuresh Kathe" <kathe.mayuresh@...>

Hello,

52 messages 2008/08/08
[#310600] Re: Ruby IDE — "Jayson Williams" <williams.jayson@...> 2008/08/08

I like working in NetBeans, but even on the Quad processor computer at

[#310603] Re: Ruby IDE — Dana Merrick <dmerrick@...> 2008/08/08

Jayson Williams wrote:

[#310610] Re: Ruby IDE — "Eric Schulte" <schulte.eric@...> 2008/08/08

To piggy-back on and emphasize the importance of Dana's point,

[#310719] Re: Ruby IDE — "Piyush Ranjan" <piyush.pr@...> 2008/08/09

I second emacs

[#310725] Re: Ruby IDE — "M. Edward (Ed) Borasky" <znmeb@...> 2008/08/09

On Sun, 2008-08-10 at 05:25 +0900, Piyush Ranjan wrote:

[#310726] Re: Ruby IDE — Matt Lawrence <matt@...> 2008/08/09

On Sun, 10 Aug 2008, M. Edward (Ed) Borasky wrote:

[#310733] Re: Ruby IDE — Joshua Ballanco <jballanc@...> 2008/08/10

Matt Lawrence wrote:

[#310814] Re: Ruby IDE — "Martin DeMello" <martindemello@...> 2008/08/11

On 8/9/08, Joshua Ballanco <jballanc@gmail.com> wrote:

[#310580] Non-Threaded Timeout? — Bryan Richardson <btrichardson@...>

Hell all,

30 messages 2008/08/08

[#310837] gem (update ?) problem — Peter Krieg <pk.hot@...>

Hello,

21 messages 2008/08/11

[#310865] Sort array by two attributes? (like sql "order by A, B") — Max Williams <toastkid.williams@...>

IN sql we can pass two arguments to the 'order by' component, and it

9 messages 2008/08/11

[#310921] Problems with accessing directory defined in ENV variables — Thomas Luedeke <thomas.luedeke@...>

Ruby is giving me pure hell trying to access directories on a mounted

10 messages 2008/08/11

[#310947] Sigh! I'm depressed. Debian vs Ruby and the backtick and subshells — John Carter <john.carter@...>

I have just strace'd weird bug to it's root cause.

20 messages 2008/08/12

[#310950] Ruby 1.9: What to Expect by Sam Ruby @ OSCON 2008 Slide Deck Adapted S6/S9 (Single-Web Page) Version — "Gerald Bauer" <geraldbauer2007@...>

Hello,

15 messages 2008/08/12
[#311073] Re: Ruby 1.9: What to Expect by Sam Ruby @ OSCON 2008 Slide Deck Adapted S6/S9 (Single-Web Page) Version — Iki Baz Castillo <ibc@...> 2008/08/12

El Martes, 12 de Agosto de 2008, Gerald Bauer escribi=F3:

[#311080] Re: Ruby 1.9: What to Expect by Sam Ruby @ OSCON 2008 Slide Deck Adapted S6/S9 (Single-Web Page) Version — "Jeremy Kemper" <jeremy@...> 2008/08/12

On Tue, Aug 12, 2008 at 1:36 PM, I=F1aki Baz Castillo <ibc@aliax.net> wrote=

[#311085] Re: Ruby 1.9: What to Expect by Sam Ruby @ OSCON 2008 Slide Deck Adapted S6/S9 (Single-Web Page) Version — Iki Baz Castillo <ibc@...> 2008/08/12

El Martes, 12 de Agosto de 2008, Jeremy Kemper escribi=F3:

[#311086] Re: Ruby 1.9: What to Expect by Sam Ruby @ OSCON 2008 Slide Deck Adapted S6/S9 (Single-Web Page) Version — Iki Baz Castillo <ibc@...> 2008/08/12

El Martes, 12 de Agosto de 2008, I=F1aki Baz Castillo escribi=F3:

[#310988] what do you think of this code? — "Ben Aurel" <ben.aurel@...>

hi

16 messages 2008/08/12
[#310992] Re: what do you think of this code? — Stefano Crocco <stefano.crocco@...> 2008/08/12

On Tuesday 12 August 2008, Ben Aurel wrote:

[#311235] Mutithreading to implement near 7000 to 10000 mssage per min — Kaja Mohaideen <kajamohaideen_2003@...>

Hello,

10 messages 2008/08/14

[#311256] Idiom of removing a particular character from a String? — "Lorenzo E. Danielsson" <danielsson.lorenzo@...>

Hi all,

12 messages 2008/08/14

[#311390] Not So Random (#173) — "Matthew Moss" <matthew.moss@...>

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

20 messages 2008/08/15

[#311427] BDD and TDD - What are they for? — "Clinton D. Judy" <cdj@...>

I'd like someone to give me very basic reasons for why I need Behavior

42 messages 2008/08/15
[#311655] Re: BDD and TDD - What are they for? — paron <rphillips@...> 2008/08/18

On Aug 16, 11:27=A0am, Eleanor McHugh <elea...@games-with-brains.com>

[#311469] firefox html, my downloaded html and firebug html different? — Adam Akhtar <adamtemporary@...>

Hi Im a relatively new rubyist and programmer in general and currently

10 messages 2008/08/16

[#311517] I wish to learn Ruby ,can anyone teach me??? — Amitanshu Gour <amitanshu_gour@...>

I am a beginner in Programming and don't have much idea about any

10 messages 2008/08/16

[#311523] writing if statement in one line with elsif condition — "Luiz Vitor Martinez Cardoso" <grabber@...>

I'm trying to convert it:

10 messages 2008/08/17

[#311553] Matrix: Need help to understand this behavior — Marcio Braga <mbraga0001@...>

a=[1]

10 messages 2008/08/17

[#311571] Security in use of contants — Kless <jonas.esp@...>

Is secure use constants?

40 messages 2008/08/17

[#311668] Hash#each vs Hash#each_pair — "Patrick Doyle" <wpdster@...>

Sorry if this is a FAQ, but I'm curious to learn the rationale behind

12 messages 2008/08/18

[#311803] Cut a string if length > n — Pål Bergström <pal@...>

What's the best way to cut a string if the length is above n characters?

15 messages 2008/08/19

[#311843] Shortest Ruby crash #49 — Limo Driver <melezov@...>

My contribution to the contest:

15 messages 2008/08/19

[#311937] A Mascot... — "Mayuresh Kathe" <kathe.mayuresh@...>

Hi,

100 messages 2008/08/20
[#311969] Re: A Mascot... — Phlip <phlip2005@...> 2008/08/20

Mayuresh Kathe wrote:

[#311979] Re: A Mascot... — "Mayuresh Kathe" <kathe.mayuresh@...> 2008/08/20

On Wed, Aug 20, 2008 at 5:51 PM, Phlip <phlip2005@gmail.com> wrote:

[#311980] Re: A Mascot... — "Michal Suchanek" <hramrach@...> 2008/08/20

On 20/08/2008, Mayuresh Kathe <kathe.mayuresh@gmail.com> wrote:

[#311983] Re: A Mascot... — "Clinton D. Judy" <cdj@...> 2008/08/20

V2hpY2ggaXMgd2h5IGEgZ3JlYXQgZ3JhcGhpYyBkZXNpZ25lciBjb3VsZCBjb21lIHVwIHdpdGgg

[#311984] Re: A Mascot... — "Mayuresh Kathe" <kathe.mayuresh@...> 2008/08/20

Clinton, what's your opinion about http://www.hexley.com/

[#312284] Re: A Mascot... — Karl von Laudermann <doodpants@...> 2008/08/22

On Aug 21, 8:26=A0pm, Joshua Ballanco <jball...@gmail.com> wrote:

[#312302] Re: A Mascot... — "Pablo Q." <paqs140482@...> 2008/08/22

I like it! :D, but If you haven=B4t read all post before please do it,

[#312305] Re: A Mascot... — "Gregory Brown" <gregory.t.brown@...> 2008/08/22

On Fri, Aug 22, 2008 at 1:22 PM, Pablo Q. <paqs140482@gmail.com> wrote:

[#311950] array of hashes - need to iterate and calulate stats but how — Adam Akhtar <adamtemporary@...>

I making a script which generates some basic stats for completed

19 messages 2008/08/20
[#311952] Re: array of hashes - need to iterate and calulate stats but how — Lex Williams <etaern@...> 2008/08/20

something like this :

[#311962] Re: array of hashes - need to iterate and calulate stats but how — "David A. Black" <dblack@...> 2008/08/20

Hi --

[#312026] Iterating through a hash — "Brian Ross" <p.brian.ross@...>

How can I iterate through a hash so that each key is modified and saved into

13 messages 2008/08/20

[#312048] unintuitive language feature (exclamation functions) — Nick Brown <ruby-forum.com@...>

I was surprised to discover that the code

20 messages 2008/08/20
[#312050] Re: unintuitive language feature (exclamation functions) — "F. Senault" <fred@...> 2008/08/20

Le 20 ao皦 2008 21:45, Nick Brown a 馗rit :

[#312054] Re: unintuitive language feature (exclamation functions) — Nick Brown <ruby-forum.com@...> 2008/08/20

F. Senault wrote:

[#312068] "num in [1,2,3,4]" in a cool way? — Iñaki Baz Castillo <ibc@...>

Hi, AFAIK in Ruby the only (or the "coolest") way to do something as:

17 messages 2008/08/20

[#312360] DoS vulnerability in REXML — Shugo Maeda <shugo@...>

Hello,

16 messages 2008/08/23
[#312384] Re: [ANN] DoS vulnerability in REXML — James Britt <james.britt@...> 2008/08/23

Shugo Maeda wrote:

[#312391] Re: [ANN] DoS vulnerability in REXML — "Christopher Dicely" <cmdicely@...> 2008/08/23

On Sat, Aug 23, 2008 at 9:28 AM, James Britt <james.britt@gmail.com> wrote:

[#312411] Re: [ANN] DoS vulnerability in REXML — James Britt <james.britt@...> 2008/08/23

Christopher Dicely wrote:

[#312378] Uptime Since... (#174) — "Matthew Moss" <matthew.moss@...>

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

26 messages 2008/08/23

[#312388] Why 'if 0' succeeds in Ruby — Phlip <phlip2005@...>

Rubiods:

21 messages 2008/08/23

[#312401] Open file, get first line, delete first line close file — Richard Schneeman <thedickster@...>

Hey, i'm trying to open a file, get the first line of the file, delete

17 messages 2008/08/23

[#312482] Moving all files in a folder to another hard drive — SpringFlowers AutumnMoon <summercoolness@...>

I have some code below to move all files in a folder to another hard

14 messages 2008/08/24

[#312573] Regular Expressions — Newb Newb <hema@...>

I have a image url like this <img src

16 messages 2008/08/25

[#312655] Unraveling binary data out of the proc filesystem on Solaris — Daniel Berger <djberg96@...>

Hi all,

13 messages 2008/08/25
[#312679] Re: Unraveling binary data out of the proc filesystem on Solaris — "Heesob Park" <phasis@...> 2008/08/26

Hi,

[#312734] Passing a block with define_method — "James Coglan" <jcoglan@...>

Hi list,

14 messages 2008/08/26

[#312739] MissingSourceFile: no such file to load -- sqlite3/database — Jo縊 Maca兊a <joao.macaiba@...>

Hi,

11 messages 2008/08/26

[#312792] Chris Pine Tutorial 99 Bottles of Beer Program — danielj <sleepingindian@...>

Just a beginner with a question about this:

15 messages 2008/08/26

[#312795] Deaf Grandma — danielj <sleepingindian@...>

Also from the Chris Pine tutorial for beginners:

20 messages 2008/08/27

[#312825] how to avoid passing by reference and how to copy objects — Adam Akhtar <adamtemporary@...>

Hi after a bit of searching and reading im quite confused by this.

12 messages 2008/08/27

[#312839] Difficult Inheritance Problem — Toby Clemson <tobyclemson@...>

Hi all,

15 messages 2008/08/27

[#312875] encrypting password on form submit? — "Amanda .." <a.etherton@...>

Hi there, I'm trying to use a form to create a user for a site. All the

19 messages 2008/08/27

[#312906] Having a difficult time with Case statements. — Chris Bailey <christopher.sean.bailey@...>

I am trying to implement a simple frontend for a text adventure that

12 messages 2008/08/27

[#312989] specifying a network interface, with a http get request — Andrew Parlane <ajp97@...>

Hi all, I'm fairly new to Ruby but have learnt a lot in the last month

13 messages 2008/08/28
[#313071] Re: specifying a network interface, with a http get request — John Pritchard-williams <monojohnny@...> 2008/08/28

Hi Andy,

[#313182] Re: specifying a network interface, with a http get request — Andrew Parlane <ajp97@...> 2008/08/29

Hey John,

[#312990] Beginner help: Problem installing sqlite3 on Windows XP — Kasper Frederiksen <kasper@...>

Hi Everyone,

11 messages 2008/08/28

[#313031] A general doubt — Rock Roll <karoljouis@...>

If I am developing a Windows application in Ruby using FxRuby or WxRuby,

28 messages 2008/08/28
[#313038] Re: A general doubt — Michael Morin <uzimonkey@...> 2008/08/28

Rock Roll wrote:

[#313070] Use a string as a method call — Chris Bailey <christopher.sean.bailey@...>

I'm trying to come up with an efficient way of using user input as a

16 messages 2008/08/28

[#313098] Please don't flame me...why is there no "++" in Ruby again ? — John Pritchard-williams <monojohnny@...>

There's must be very good simple reason why there is no 'x++' method

24 messages 2008/08/28
[#313100] Re: Please don't flame me...why is there no "++" in Ruby again ? — Joel VanderWerf <vjoel@...> 2008/08/28

John Pritchard-williams wrote:

[#313164] Re: Please don't flame me...why is there no "++" in Ruby again ? — David Masover <ninja@...> 2008/08/29

On Thursday 28 August 2008 16:25:59 Joel VanderWerf wrote:

[#313131] Class === — "RubyTalk@..." <rubytalk@...>

I need help with === and Objects

20 messages 2008/08/29
[#313135] Re: Class === — "Patrick Doyle" <wpdster@...> 2008/08/29

and I would also like to know why

[#313196] Computing folder size - do you have something cleaner than this ? — Thibaut Barr鑽e <thibaut.barrere@...>

Hi guys,

11 messages 2008/08/29

[#313242] Where the Required Things Are (#175) — "Matthew Moss" <matthew.moss@...>

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

21 messages 2008/08/29

[#313379] instance_eval/class_eval including/extending modules — Pedro Silva <ei04065@...>

Consider the following example:

14 messages 2008/08/30
[#313401] Re: instance_eval/class_eval including/extending modules — "David A. Black" <dblack@...> 2008/08/31

HI --

[#313428] Re: instance_eval/class_eval including/extending modules — Pedro Silva <ei04065@...> 2008/08/31

David, thanks for your reply.

[#313432] Re: instance_eval/class_eval including/extending modules — "David A. Black" <dblack@...> 2008/08/31

Hi --

[#313399] Difference between dir/**/* and dir/*? — Ben Johnson <bjohnson@...>

I've noticed the following when specifying a wildcard array of files:

14 messages 2008/08/31

Request for feedback, suggestions, contributions.

From: Kenneth McDonald <kenneth.m.mcdonald@...>
Date: 2008-08-28 15:34:30 UTC
List: ruby-talk #313014
I'm attempting to write a module whose classes will make it easier to  
construct and work with regular expressions. The two, somewhat self  
explanatory files (main and test) are given below. I would be grateful  
for feedback, especially on better ways of doing things. Also note  
that I am developing on JRuby, so currently JRuby re sytax is more  
supported than Ruby syntax.

Check out the second (test) file for simple examples of use.

Thanks,
Ken

File 'rex.rb'
-------------------
=begin rdoc
'rex.rb' is a file that provide classes intended to make it easier to  
develop
and use regular expressions. A primary feature is that it allows one  
to easily
construct larger regular expressions out of smaller regular  
expressions. The
other main feature is that it provides (or will provide) many  
functions that
make it easier to apply regular expressions in useful ways. I also  
believe that,
thought it is more verbose than standard Regexps, it provides much  
more readable
code when constructing complex regular expressions.

rex is not intended to be comprehensive; I don't have time for that.  
My hope is
that it will be useful for the 95% of 'common case' re's.
=end

CHARACTERS = {
   :dot => "\\t",
   :tab => "\\t",
   :vtab => "\\v",
   :newline => "\\n",
   :return => "\\r",
   :backspace => "\\b",
   :form_feed => "\\f",
   :bell => "\\a",
   :esc => "\\e",
   :word_char => "\\w",
   :non_word_char => "\\W",
   :whitespace_char => "\\s",
   :non_whitespace_char => "\\S",
   :digit_char => "\\d",
   :non_digit_char => "\\D"
}

class Rex

   attr_writer :is_group

=begin rdoc
Create a new Rex pattern with _string_ as the pattern that will be  
passed to
Regexp. This is used by other Rex functions; you can also use it to  
create
a 'raw' pattern.
=end
   def initialize(string)
     @pat = string
     @is_group = false
     @regexp = Regexp.new(@pat)
   end

   def index(string, start=0)
     return string.index(@regexp, start)
   end

=begin rdoc
yields each match in the string in succession
=end
   def each(string)
     start = 0
     while true:
       i = string.index(@regexp, start)
       print "MATCHED #{@regexp.inspect} AT #{i}!\n"
       if i == nil; break; end
       md = $~
       yield md
       if md.end(0) == start
         start = start + 1
       else
         start = md.end(0)
       end
     end
   end
=begin rdoc
Same as =~ on the corresponding Regexp
=end
   def =~(string)
     return @regexp =~ string
   end

=begin rdoc
Returns the pattern associated with this Rex instance. This is the  
string is
passed to Regexp to create a new Regexp.
=end
   def pat
     return @pat
   end

   def group
     if @is_group
       return self
     else
       result = Rex.new("(?:#{@pat})")
       result.is_group = true
       return result
     end
   end

=begin rdoc
Regular expression concatenation; Lit.new("ab") + Lit.new("cd") will  
produce
a Rex that has the same meaning as the Regexp /abcd/ (though the  
pattern will
be different.
=end
   def +(other)
     return Rex.new(self.group.pat + other.group.pat)
   end

=begin rdoc
Used to define a named group. If _rex_ is a Rex instance with an  
internal pattern
_pat_, then _rex_['name'] produces a new Rex with pattern (? 
<name>_pat_).
=end
   def [](name)
     result = Rex.new("(?<#{name}>#{@pat})")
     result.is_group = true
     return result
   end

   #    def +(other)
   #        r1 = self
   #        r1 = r1.wrap_if_not("+")
   #        other = other.wrap_if_not("+")
   #        r = Regexp.new(r1 + other)
   #        r.operator = "+"
   #        return r
   #    end


=begin rdoc
Regular expression alternation. Lit.new("ab") | Lit.new("cd") will  
produce
a Rex that has the same meaning as the Regexp /ab|cd/ (though the  
pattern will
be different.
=end
   def |(other)
     return Rex.new(self.group.pat + "|" + other.group.pat)
   end

=begin rdoc
Same as the corresponding *match* method in Regexp.
=end
   def match(string)
     return @regexp.match(string)
   end

=begin rdoc
Returns a new Rex that is an optional version of this one;  
Lit.new('a').optional
has the same effect as the Regexp /a?/
=end
   def optional
     return Rex.new(self.group.pat + "?")
   end

   # Invoke up a Rex to indicate it is naturally grouped, i.e. does  
not need to
   # be surrounded with parens before being put into another Rex.
   def natural_group # :nodoc:
     @is_group = true
     return self
   end

=begin rdoc
Defines regular expression repetitions. Lit.new('a').n(3) is the same as
/a{3,}/, while Lit.new(3..7) is the same as /a{3,7}/. use 0 or 1 to  
achieve
the same effect as the * and + Regexp operators. Tri-period ranges of  
the form
3...8 are allowed, and have the same meaning as one would expect, i.e.  
that
range give the same result as 3..7.
=end
   def n(repetitions)
     if repetitions.is_a?(Integer)
       return Rex.new(self.group.pat +  
"{#{repetitions},}").natural_group
     elsif repetitions.is_a?(Range)
       ending = repetitions.end
       if repetitions.exclude_end?
         ending -= 1
       end
       return Rex.new(self.group.pat +  
"{#{repetitions.begin},#{ending}}").natural_group
     end
   end

=begin rdoc
Same as method *n*, but nongreedy.
=end
   def n?(repetitions)
     if repetitions.is_a?(Integer)
       return Rex.new(self.group.pat +  
"{#{repetitions},}?").natural_group
     elsif repetitions.is_a?(Range)
       ending = repetitions.end
       if repetitions.exclude_end?
         ending -= 1
       end
       return Rex.new(self.group.pat +  
"{#{repetitions.begin},#{ending}}?").natural_group
     end
   end

   def to_s
     return @pat
   end
end

=begin rdoc
Create a new literal that will match exactly that string. This handles  
Regexp
escaping for you, so you do not need to worry about handling  
characters with
special meanings in Regexp.
=end
class Lit < Rex
   def initialize(string)
     @pat = Regexp.escape(string)
     @regexp = Regexp.new(@pat)
     @is_group = false
   end
end

class Chars < Rex
=begin rdoc
Creates a character class that matches those characters given in  
_include_,
except for those given in _exclude_. Each of _include_ and _exclude_  
should be
one of:

* A string, in which case it defines the set of characters to be  
included or excluded.
* A double-dot (x..y) range, which will define a range of characters  
to be included or excluded.
* A list of strings and ranges, which have the same meanings as above  
and are combined to produce the set of characters to be included or  
excluded.
* A symbol, which is used to denote one of the special character  
classes.

Note that Chars defines no special characters.
_include_:: The set of characters to be included in the class. Include  
may be nil or the empty string, if you don't want to include  
characters in the class.
_exclude_:: The set of characters to be excluded from the class.  
Defaults to nil.
=end
   def initialize(include, exclude=nil)

     def list_to_chars(list)
       chars = ""
       list.each {|e|
         if e.is_a?(String)
           chars << Regexp.escape(e)
         elsif e.is_a?(Range)
           chars << Regexp.escape(e.begin) << "-" <<  
Regexp.escape(e.end)
         elsif e.is_a?(Symbol)
           chars << "[:" << e.to_s << ":]"
         end
       }
       return chars
     end

     if include == nil or include == ""
       include = nil
     elsif include.is_a?(Array)
       include = list_to_chars(include)
     else
       include = list_to_chars([include])
     end

     if exclude.is_a?(Array)
       exclude = list_to_chars(exclude)
     elsif exclude != nil
       exclude = list_to_chars([exclude])
     end

     if exclude == nil
       chars = ("[#{include}]")
     elsif include == nil
       chars = "[^#{exclude}]"
     else
       chars = ("[#{include}&&[^#{exclude}]]")
     end

     @pat = chars
     @regexp = Regexp.new(@pat)
     @is_group = true
   end
end







File 'rex_test.rb'
-----------------------
$:.unshift File.join(File.dirname(__FILE__),'..','lib')

require 'test/unit'
require 'rex'

class RexTest < Test::Unit::TestCase
   def test_simple
     posint = Rex.new('[0-9]+')
     posfloat = posint + (Lit.new('.') + posint).optional
     float = (Lit.new('+')|Lit.new('-')).optional + posfloat
     complex = float['re'] + (Lit.new('+')|Lit.new('-')) +  
posfloat['im'] + Lit.new('i')
     print complex
     assert_equal(0, posint =~ "123")
     assert_equal(0, posfloat =~ "123.45")
     assert_equal(0, posfloat =~ "123")
     assert_equal("3.45", complex.match(" 3.45-2i")['re'])
   end

   def test_repetitions
     assert_equal("(?:a){3,}", Lit.new('a').n(3).pat)
     assert_equal("(?:a){3,5}", Lit.new('a').n(3..5).pat)
     assert_equal("(?:a){3,4}", Lit.new('a').n(3...5).pat)
     assert_equal("(?:a){3,}?", Lit.new('a').n?(3).pat)
     assert_equal("(?:a){3,5}?", Lit.new('a').n?(3..5).pat)
     assert_equal("(?:a){3,4}?", Lit.new('a').n?(3...5).pat)
   end

   def test_char_class
     assert_equal("[abc]", Chars.new("abc").pat)
     assert_equal("[^abc]", Chars.new(nil, "abc").pat)
     assert_equal("[abc&&[^de]]", Chars.new("abc", "de").pat)
     assert_equal("[abct-z&&[^n-u]]", Chars.new(["abc", "t".."z"],  
"n".."u").pat)
     assert_equal("[[:alnum:]]", Chars.new(:alnum).pat)
   end

   def test_index
     assert_equal(3, Rex.new("a").index("bcda"))
     assert_equal(3, Lit.new("a").index("bcda"))
   end

   def test_each
     pat = Lit.new('a').n(1)
     s = "aababbaaababb"
     result = []
     pat.each(s) {|md|
       result << md[0]
     }
     assert_equal(["aa", "a", "aaa", "a"], result)
   end
end


In This Thread

Prev Next