Ruby T-Shirt Idea

http://www.rubycentral.com/book/

Or if you meant a specific reference for each_line, see
http://www.rubycentral.com/book/ref_c_io.html#IO.each_line

···

On Thu, Jul 10, 2003 at 02:16:15PM +0900, Daniel Carrera wrote:

Or could someone give me a link to PickAxe so I can look it up?

Or you can use nasty perlisms:

$ ruby -ne ‘print if /a/’ myfile
cat
zebra

Personally I think $_ should be abolished :slight_smile:

Something that shows either the OO-nature of Ruby, or blocks/iterators in
action, has got to be a good thing.

Regards,

Brian.

···

On Thu, Jul 10, 2003 at 02:27:07PM +0900, Daniel Carrera wrote:

I just thought of a dead give-away:

dcarrera ~ $ cat myfile
cat
dog
horse
zebra
tiger
dcarrera ~ $ grep a myfile
cat
zebra
dcarrera ~ $ ruby -e ‘puts ARGF.grep(/a/)’ myfile
cat
zebra

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Okay, ignore my last question (except the one about a link to PicAxe). I
just figured the
syntax (basically by trying every possible permutation).

Now I have a new question: Turning a string into a regex.
Example:

dcarrera ~ $ irb

var = “he”
=> “he”
str = “hello world”
=> “hello world”
str =~ /var/
=> nil

What am I doing wrong?

You can do str =~ /#{var}/ I think…

Hal

···

----- Original Message -----
From: “Daniel Carrera” dcarrera@math.umd.edu
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Thursday, July 10, 2003 12:21 AM
Subject: Re: Ruby T-Shirt Idea

They’re the same if you omit the fact that I forgot about Enumerable#grep :wink:
It turns out that $<, $DEFAULT_INPUT and ARGF are synonyms.

IMHO one semicolon is equivalent to one line-break but we can still make
it a one-liner without cheating:

re = ARGV.shift and puts ARGF.grep(/#{re}/)

However, I don’t quite like this example, it feels perlish.
I’d rather show singleton methods at work, or blocks, or metaclasses…

···

On Thu, Jul 10, 2003 at 02:50:21PM +0900, Daniel Carrera wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thu, Jul 10, 2003 at 02:47:16PM +0900, Mauricio Fernández wrote:

What about

require ‘English’
re = ARGV.shift
$DEFAULT_INPUT.each{|x| puts x if x =~ /#{re}/}

??

It’s two lines if you use ‘$<’…

Did you see mine? It was one line! (with a semicolon though :slight_smile:


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Problem solving under Linux has never been the circus that it is under
AIX.
– Pete Ehlke in comp.unix.aix

In article 035a01c346a5$7740f600$0300a8c0@austin.rr.com,

[…]

BTW, var = Regexp.new(Regexp.escape(var)) will
also do that conversion… probably more than
two ways… :wink:

As for interpolating a variable into a regex,
I’m not sure whether it does automatic escaping
or not. I’d like to think it does, but there
may be some good reason it doesn’t. Too lazy to
test right now…

It doesn’t automatically escape the interpolated thing and that’s a good
thing. Sometimes I construct alternations dynamically e.g.

[mike@ratdog mike]$ irb --simple-prompt

words = %w{foo bar baz}
=> [“foo”, “bar”, “baz”]
match_a_word = /\b(?:#{words.join(‘|’)})\b/
=> /\b(?:foo|bar|baz)\b/
“April fool” =~ match_a_word
=> nil
“this has a foo in it” =~ match_a_word
=> 11

and I don’t want the interpolation to quietly “save me from myself.” Of
course it’s my responsibility to escape things which need escaping.

Sometimes I do miss a perl-like \Q in an interpolated string, but the
power of #{ … } more than makes up for it.

Mike

···

Hal E. Fulton hal9000@hypermetrics.com wrote:


mike@stok.co.uk | The “`Stok’ disclaimers” apply.
http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA
mike@exegenix.com | Fingerprint 0570 71CD 6790 7C28 3D60
http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA

Whoohoo!!!

dcarrera ~ $ alias mygrep=“ruby -e ‘re=ARGV.shift; puts ARGF.grep(/#{re}/)’”
dcarrera ~ $ mygrep a myfile
cat
zebra

Whheeee!!!


Daniel Carrera | OpenPGP fingerprint:
Graduate TA, Math Dept | 6643 8C8B 3522 66CB D16C D779 2FDD 7DAC 9AF7 7A88
UMD (301) 405-5137 | http://www.math.umd.edu/~dcarrera/pgp.html

···

On Thu, Jul 10, 2003 at 02:27:45PM +0900, Hal E. Fulton wrote:

What am I doing wrong?

You can do str =~ /#{var}/ I think…

Did you see mine? It was one line! (with a semicolon though :slight_smile:

They’re the same if you omit the fact that I forgot about Enumerable#grep :wink:
It turns out that $<, $DEFAULT_INPUT and ARGF are synonyms.

I didn’t know that. I should have guessed.

IMHO one semicolon is equivalent to one line-break but we can still make
it a one-liner without cheating:

re = ARGV.shift and puts ARGF.grep(/#{re}/)

However, I don’t quite like this example, it feels perlish.
I’d rather show singleton methods at work, or blocks, or metaclasses…

Okay, so we agree on:

re = ARGV.shift;
ARGF.each{|x| puts x if x =~ /#{re}/}

It’s Rubyish, and it avoids the perlishms like “$<” (akward variable names) and the “and”.
A slight modification would be:

re = ARGV.shift;
puts ARGF.map{|x| x if x =~ /#{re}/}.compact

I’m not sure which one I like better.


Daniel Carrera | OpenPGP fingerprint:
Graduate TA, Math Dept | 6643 8C8B 3522 66CB D16C D779 2FDD 7DAC 9AF7 7A88
UMD (301) 405-5137 | http://www.math.umd.edu/~dcarrera/pgp.html

···

On Thu, Jul 10, 2003 at 03:18:01PM +0900, Mauricio Fernández wrote:

Just out of curiosity, what exactly is are the candidates for the Ruby
T-Shirt? Or is that too much on-topic at this point?

Would it still be in good taste to make a suggestion?

Sean O'Dell

In article 3DhPa.102688$a51.96868@news02.bloor.is.net.cable.rogers.com,
mike@ratdog.stok.co.uk (Mike Stok) writes:

It doesn’t automatically escape the interpolated thing and that’s a good
thing. Sometimes I construct alternations dynamically e.g.

[mike@ratdog mike]$ irb --simple-prompt

words = %w{foo bar baz}
=> [“foo”, “bar”, “baz”]
match_a_word = /\b(?:#{words.join(‘|’)})\b/
=> /\b(?:foo|bar|baz)\b/
“April fool” =~ match_a_word
=> nil
“this has a foo in it” =~ match_a_word
=> 11

How about /\b#{Regexp.alt words}\b/ using following Regexp.alt:

def Regexp.alt(*args)
if args.empty?
/(?!)/
else
Regexp.compile(args.map {|arg| Regexp === arg ? arg.to_s : Regexp.quote(arg) }.join(‘|’))
end
end

···


Tanaka Akira

Hi,

···

At Thu, 10 Jul 2003 15:26:14 +0900, Daniel Carrera wrote:

Okay, so we agree on:

re = ARGV.shift;
ARGF.each{|x| puts x if x =~ /#{re}/}

It’s Rubyish, and it avoids the perlishms like “$<” (akward variable names) and the “and”.
A slight modification would be:

re = ARGV.shift;
puts ARGF.map{|x| x if x =~ /#{re}/}.compact

They waits until all input end.

ARGF.grep(Regexp.new(ARGV.shift)) {|l| puts l}

or

ARGF.grep(Regexp.new(ARGV.shift), &method(:puts))


Nobu Nakada

Incidentally, you could make it more efficient by building the regex only
once:

 re = /#{ARGV.shift}/
 ARGF.each{|x| puts x if x =~ re}

Regards,

Brian.

···

On Thu, Jul 10, 2003 at 03:26:14PM +0900, Daniel Carrera wrote:

Okay, so we agree on:

re = ARGV.shift;
ARGF.each{|x| puts x if x =~ /#{re}/}

Just out of curiosity, what exactly is are the candidates for the Ruby
T-Shirt? Or is that too much on-topic at this point?

Would it still be in good taste to make a suggestion?

Heh… fire away. Let there be T-shirts.

I’m leaning away from the idea of a “comparative”
thing, though… let’s not promote language wars.

Hal

···

----- Original Message -----
From: “Sean O’Dell” sean@REMOVEME.celsoft.com.web-hosting.com
Newsgroups: comp.lang.ruby
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Thursday, July 10, 2003 5:43 PM
Subject: Re: Ruby T-Shirt Idea


Hal Fulton
hal9000@hypermetrics.com

Just out of curiosity, what exactly is are the candidates for the Ruby
T-Shirt? Or is that too much on-topic at this point?

There isn’t a contest or anything, I am going to make a T-shirt for
myself. Just though I would throw it out there.

As for my design…

The reason I am totally hooked on Ruby is that it is a very clean
Object Oriented Language without alot of extra garbage. That is why my
shirt design has a complete class. Personally, I am much less
attracted to the macho “one line powerhouse” type stuff, as it is a
bit standoffish. ( Built in Grep is very cool though :wink:

I am also not looking to say “My language is the best”, but more, hey
if you are looking for a new language to learn, you HAVE to give Ruby
a spin. It is sooo cool and insta-grok.

Here is a color preview ( no images just CSS )
http://www.ozten.com/random/ruby-shirt.html

“Hal E. Fulton” hal9000@hypermetrics.com wrote in message
news:062c01c34737$e33ff9e0$0300a8c0@austin.rr.com

···

----- Original Message -----
From: “Sean O’Dell” sean@REMOVEME.celsoft.com.web-hosting.com

Just out of curiosity, what exactly is are the candidates for the Ruby
T-Shirt? Or is that too much on-topic at this point?

Would it still be in good taste to make a suggestion?

Heh… fire away. Let there be T-shirts.

I’m leaning away from the idea of a “comparative”
thing, though… let’s not promote language wars.

I was thinking of just the Japanese symbol(s) for Ruby in a rich red color
on a simple white t-shirt. That might not be very “promotional” but I,
personally, would appreciate the succinctness.

Sean O'Dell

Just out of curiosity, what exactly is are the candidates for the Ruby
T-Shirt? Or is that too much on-topic at this point?

There isn’t a contest or anything, I am going to make a T-shirt for
myself. Just though I would throw it out there.

As for my design…

The reason I am totally hooked on Ruby is that it is a very clean
Object Oriented Language without alot of extra garbage. That is why my
shirt design has a complete class. Personally, I am much less
attracted to the macho “one line powerhouse” type stuff, as it is a
bit standoffish. ( Built in Grep is very cool though :wink:

I am also not looking to say “My language is the best”, but more, hey
if you are looking for a new language to learn, you HAVE to give Ruby
a spin. It is sooo cool and insta-grok.

Here is a color preview ( no images just CSS )
http://www.ozten.com/random/ruby-shirt.html

I do hope the street_cred bit is true. It’s my
perception that Ruby is gaining in popularity,
but someone told me a few days ago that Ruby
was “dead in the water.” I raised my eyebrow
and expressed the opposite opinion, of course.

Hal

···

----- Original Message -----
From: “Austin King” shout@ozten.com
Newsgroups: comp.lang.ruby
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Thursday, July 10, 2003 8:46 PM
Subject: Re: Ruby T-Shirt Idea


Hal Fulton
hal9000@hypermetrics.com

Before committing to cotton, could I recommend
this patch for your T-shirt?:

— DfB\TEMP\clruby\TShirt_o.rb Fri Jul 11 06:49:26 2003
+++ DfB\TEMP\clruby\TShirt_p.rb Fri Jul 11 06:50:16 2003
@@ -4,5 +4,5 @@
super( name, talent )
@productivity = CodeFu.MASTER * talent

  • @stress_level = @stress_level / 2
  • @stress_level /= 2
    @street_cred = true
    end

I think the fact that (2 * @stress) / 2 == @stress
could cause some embarrassment before the print has faded.

Another option could be:

  • @stress_level = @stress_level / 2
  • @stress_level.shift

daz

(Taking a break from ‘viral’ licensing issues - Yo Lyle !)

···

“Austin King” shout@ozten.com wrote:

[…]
Here is a color preview ( no images just CSS )
http://www.ozten.com/random/ruby-shirt.html

“Hal E. Fulton” hal9000@hypermetrics.com wrote in message
news:062c01c34737$e33ff9e0$0300a8c0@austin.rr.com

From: “Sean O’Dell” sean@REMOVEME.celsoft.com.web-hosting.com

Just out of curiosity, what exactly is are the candidates for the Ruby
T-Shirt? Or is that too much on-topic at this point?

Would it still be in good taste to make a suggestion?

Heh… fire away. Let there be T-shirts.

I’m leaning away from the idea of a “comparative”
thing, though… let’s not promote language wars.

I was thinking of just the Japanese symbol(s) for Ruby in a rich red color
on a simple white t-shirt. That might not be very “promotional” but I,
personally, would appreciate the succinctness.

Done long ago. See Ruby.shop at rubyhacker.com

Doesn’t have a URL or anything, though.

Hal

···

----- Original Message -----
From: “Sean O’Dell” sean@REMOVEME.celsoft.com.web-hosting.com
Newsgroups: comp.lang.ruby
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Thursday, July 10, 2003 6:44 PM
Subject: Re: Ruby T-Shirt Idea

----- Original Message -----

irb(main):001:0> 5.shift
NameError: undefined method `shift’ for 5:Fixnum

···

On Fri, Jul 11, 2003 at 03:31:00PM +0900, daz wrote:

  • @stress_level = @stress_level / 2
  • @stress_level.shift

daz wrote:

Here is a color preview ( no images just CSS )
http://www.ozten.com/random/ruby-shirt.html

Before committing to cotton, could I recommend
this patch for your T-shirt?:

— DfB\TEMP\clruby\TShirt_o.rb Fri Jul 11 06:49:26 2003
+++ DfB\TEMP\clruby\TShirt_p.rb Fri Jul 11 06:50:16 2003
@@ -4,5 +4,5 @@
super( name, talent )
@productivity = CodeFu.MASTER * talent

  • @stress_level = @stress_level / 2
  • @stress_level /= 2
    @street_cred = true
    end

While we’re picking nits, I noticed that “CodeFu.MASTER” doesn’t work if
MASTER is a constant (which seems natural). Ruby thinks it is a method
due to the “.”, so perhaps CodeFu::MASTER would be better.

···

“Austin King” shout@ozten.com wrote:


([ Kent Dahl ]/)_ ~ [ http://www.pvv.org/~kentda/ ]/~
))_student_/(( _d L b_/ (pre-) Master of Science in Technology )
( __õ|õ// ) )Industrial economics and technological management(
_
/ö____/ (_engineering.discipline=Computer::Technology)

I have been through a series of interviews recently – people who have finally gotten around to reading The Pragmatic Programmer – and have had my Rubyist status received positively.

-austin

···

On Fri, 11 Jul 2003 15:22:57 +0900, Hal E. Fulton wrote:

I do hope the street_cred bit is true. It’s my
perception that Ruby is gaining in popularity,
but someone told me a few days ago that Ruby
was “dead in the water.” I raised my eyebrow
and expressed the opposite opinion, of course.


austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2003.07.11
* 10:48:43