[#3986] Re: Principle of least effort -- another Ruby virtue. — Andrew Hunt <andy@...>

> Principle of Least Effort.

14 messages 2000/07/14

[#4043] What are you using Ruby for? — Dave Thomas <Dave@...>

16 messages 2000/07/16

[#4139] Facilitating Ruby self-propagation with the rig-it autopolymorph application. — Conrad Schneiker <schneik@...>

Hi,

11 messages 2000/07/20

[ruby-talk:04163] Re: Regex question

From: faatdilac@...
Date: 2000-07-21 18:17:25 UTC
List: ruby-talk #4163
In article <8l9u9k$jd0$1@nnrp1.deja.com>,
  hal9000@hypermetrics.com wrote:
> The program here is totally frivolous -- it prints out the
> obnoxious drinking song "99 Bottles of Beer on the Wall."
>
> But the regex question is real. I'm not doing the substituting
> the "proper" way -- a block with \1 \2 and so on.
>
> Would someone care to improve this?
>
> Of course, comments unrelated to the regex are welcome also.
> But it's not really intended to be elegant or efficient. :)
>
> Thanks,
> Hal
>
> --------------
> class Inebriation
>   What="N bottle of beer"
>   Where=" on the wall"
>   How="Take one down and pass it around,\n"
>
>   Verse = What + Where + ",\n" + What + ";\n" + How + What + Where
+ "!
> \n\n"
>
>   def drink(*brew)
>     brew.each do |x|
>       cold_one = Verse.sub /N/,x.to_s
>       cold_one.sub! /N/,x.to_s
>       cold_one.sub! /N/,(x-1).to_s
>       cold_one.sub! /bottle /,"bottles " unless x == 1
>       cold_one.sub! /bottle /,"bottles " unless x == 1
>       regex = Regexp.new("#{x-1} bottle ")
>       cold_one.sub! regex,"#{x-1} bottles " unless (x-1) == 1
>       print cold_one
>     end
>   end
> end
>
> blitzkrieg = Inebriation.new

Better is:
bottle_beer = Inebriation.new

blitzkrieg is history, neither Bjorn Borg nor Boris Becker like that
term as nickname. The usage of 'blitzkrieg' is not considered as
tasteful and peaceful in some communities.

>
> beer=(1..99).to_a.reverse!
>
> blitzkrieg.drink *beer

disto as above

> --------------
>
> --
> Hal Fulton
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>

faatdilac


Sent via Deja.com http://www.deja.com/
Before you buy.

In This Thread

Prev Next