[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: How to shoot yourself in the foot in Ruby

John Carter

12/6/2006 9:20:00 PM

12 Answers

Harold Hausman

12/7/2006 2:11:00 AM

0

On 12/7/06, John Carter <john.carter@tait.co.nz> wrote:
> On Thu, 7 Dec 2006, Edwin Fine wrote:
>
> > Jeremy Henty wrote:
> >> On 2006-12-05, Edwin Fine <efine145-nospam01@usa.net> wrote:
> >>
> >>> How about a Ruby Quiz for the funniest way to shoot yourself in the
> >>> foot with Ruby?
>
> #!/bin/ruby -w
>
> me = File.read( __FILE__)
> open( __FILE__, 'w') do |f|
> f.syswrite( me.sub( /ruby -w/, 'sh'))
> end
>
> Although this works fairly well too...
>
> #!/bin/ruby -w
>
> me = File.read( __FILE__)
> open( __FILE__, 'w') do |f|
> f.syswrite( me.sub( /-w/, 'sh'))
> end
>

Thats cute.

How about this?
Object.constants.each do |x| eval( "#{x} = nil" ) end

Seems to shoot irb in the foot, for various values of foot, like head.

(:,
-Harold

Eric Hodel

12/7/2006 2:55:00 AM

0

On Dec 6, 2006, at 18:11 , Harold Hausman wrote:
> On 12/7/06, John Carter <john.carter@tait.co.nz> wrote:
>> On Thu, 7 Dec 2006, Edwin Fine wrote:
>>
>> > Jeremy Henty wrote:
>> >> On 2006-12-05, Edwin Fine <efine145-nospam01@usa.net> wrote:
>> >>
>> >>> How about a Ruby Quiz for the funniest way to shoot yourself
>> in the
>> >>> foot with Ruby?
>>
>> #!/bin/ruby -w
>>
>> me = File.read( __FILE__)
>> open( __FILE__, 'w') do |f|
>> f.syswrite( me.sub( /ruby -w/, 'sh'))
>> end
>>
>> Although this works fairly well too...
>>
>> #!/bin/ruby -w
>>
>> me = File.read( __FILE__)
>> open( __FILE__, 'w') do |f|
>> f.syswrite( me.sub( /-w/, 'sh'))
>> end
>>
>
> Thats cute.
>
> How about this?
> Object.constants.each do |x| eval( "#{x} = nil" ) end
>
> Seems to shoot irb in the foot, for various values of foot, like head.

eval? please!

Object.constants.each do |c| Object.send :remove_const, c end

--
Eric Hodel - drbrain@segment7.net - http://blog.se...

I LIT YOUR GEM ON FIRE!


Harold Hausman

12/7/2006 2:58:00 AM

0

On 12/7/06, Eric Hodel <drbrain@segment7.net> wrote:
> On Dec 6, 2006, at 18:11 , Harold Hausman wrote:
> >
> > How about this?
> > Object.constants.each do |x| eval( "#{x} = nil" ) end
> >
> > Seems to shoot irb in the foot, for various values of foot, like head.
>
> eval? please!
>
> Object.constants.each do |c| Object.send :remove_const, c end
>

ahhhh, now that's the Ruby Way.

I'm such a noob,
-Harold

M. Edward (Ed) Borasky

12/7/2006 5:21:00 AM

0

Eric Hodel wrote:
> On Dec 6, 2006, at 18:11 , Harold Hausman wrote:
>> On 12/7/06, John Carter <john.carter@tait.co.nz> wrote:
>>> On Thu, 7 Dec 2006, Edwin Fine wrote:
>>>
>>> > Jeremy Henty wrote:
>>> >> On 2006-12-05, Edwin Fine <efine145-nospam01@usa.net> wrote:
>>> >>
>>> >>> How about a Ruby Quiz for the funniest way to shoot yourself in the
>>> >>> foot with Ruby?
>>>
>>> #!/bin/ruby -w
>>>
>>> me = File.read( __FILE__)
>>> open( __FILE__, 'w') do |f|
>>> f.syswrite( me.sub( /ruby -w/, 'sh'))
>>> end
>>>
>>> Although this works fairly well too...
>>>
>>> #!/bin/ruby -w
>>>
>>> me = File.read( __FILE__)
>>> open( __FILE__, 'w') do |f|
>>> f.syswrite( me.sub( /-w/, 'sh'))
>>> end
>>>
>>
>> Thats cute.
>>
>> How about this?
>> Object.constants.each do |x| eval( "#{x} = nil" ) end
>>
>> Seems to shoot irb in the foot, for various values of foot, like head.
>
> eval? please!
>
> Object.constants.each do |c| Object.send :remove_const, c end
>
> --Eric Hodel - drbrain@segment7.net - http://blog.se...
>
> I LIT YOUR GEM ON FIRE!
>
>
>
how about this?

sudo rm -fr /usr/lib/ruby



--
M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC(P)
http://borasky-research.blo...

If God had meant for carrots to be eaten cooked, He would have given rabbits fire.


x1

12/7/2006 5:31:00 AM

0

As close to being shot in the foot as I could get:

irb(main):008:0> puts ENV['OS']
Windows_NT



On 12/7/06, M. Edward (Ed) Borasky <znmeb@cesmail.net> wrote:
> Eric Hodel wrote:
> > On Dec 6, 2006, at 18:11 , Harold Hausman wrote:
> >> On 12/7/06, John Carter <john.carter@tait.co.nz> wrote:
> >>> On Thu, 7 Dec 2006, Edwin Fine wrote:
> >>>
> >>> > Jeremy Henty wrote:
> >>> >> On 2006-12-05, Edwin Fine <efine145-nospam01@usa.net> wrote:
> >>> >>
> >>> >>> How about a Ruby Quiz for the funniest way to shoot yourself in the
> >>> >>> foot with Ruby?
> >>>
> >>> #!/bin/ruby -w
> >>>
> >>> me = File.read( __FILE__)
> >>> open( __FILE__, 'w') do |f|
> >>> f.syswrite( me.sub( /ruby -w/, 'sh'))
> >>> end
> >>>
> >>> Although this works fairly well too...
> >>>
> >>> #!/bin/ruby -w
> >>>
> >>> me = File.read( __FILE__)
> >>> open( __FILE__, 'w') do |f|
> >>> f.syswrite( me.sub( /-w/, 'sh'))
> >>> end
> >>>
> >>
> >> Thats cute.
> >>
> >> How about this?
> >> Object.constants.each do |x| eval( "#{x} = nil" ) end
> >>
> >> Seems to shoot irb in the foot, for various values of foot, like head.
> >
> > eval? please!
> >
> > Object.constants.each do |c| Object.send :remove_const, c end
> >
> > --Eric Hodel - drbrain@segment7.net - http://blog.se...
> >
> > I LIT YOUR GEM ON FIRE!
> >
> >
> >
> how about this?
>
> sudo rm -fr /usr/lib/ruby
>
>
>
> --
> M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC(P)
> http://borasky-research.blo...
>
> If God had meant for carrots to be eaten cooked, He would have given rabbits fire.
>
>
>

Paul Lutus

12/7/2006 8:48:00 AM

0

M. Edward (Ed) Borasky wrote:

/ ...

> how about this?
>
> sudo rm -fr /usr/lib/ruby

Gee, I hope the newbies don't try this just to see what happens. If they
"succeed", they might then try for the more concise, powerful form, which I
won't post an example of.

--
Paul Lutus
http://www.ara...

Max Muermann

12/7/2006 9:00:00 PM

0

On 12/7/06, x1 <caldridge@gmail.com> wrote:
> As close to being shot in the foot as I could get:
>
> irb(main):008:0> puts ENV['OS']
> Windows_NT
>

That's missing your foot altogether and shooting yourself in the head instead...

max

M. Edward (Ed) Borasky

12/8/2006 4:03:00 AM

0

Paul Lutus wrote:
> M. Edward (Ed) Borasky wrote:
>
> / ...
>
>
>> how about this?
>>
>> sudo rm -fr /usr/lib/ruby
>>
>
> Gee, I hope the newbies don't try this just to see what happens. If they
> "succeed", they might then try for the more concise, powerful form, which I
> won't post an example of.
>
I'm just a curmudgeon. My example wasn't in Ruby, either. It's really an
example of how to shoot yourself in the foot *without* Ruby. :)


--
M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC(P)
http://borasky-research.blo...

If God had meant for carrots to be eaten cooked, He would have given rabbits fire.


x1

12/8/2006 4:49:00 AM

0

If you wrapped it with system() in ruby, would it return true or false?

On 12/7/06, M. Edward (Ed) Borasky <znmeb@cesmail.net> wrote:
> Paul Lutus wrote:
> > M. Edward (Ed) Borasky wrote:
> >
> > / ...
> >
> >
> >> how about this?
> >>
> >> sudo rm -fr /usr/lib/ruby
> >>
> >
> > Gee, I hope the newbies don't try this just to see what happens. If they
> > "succeed", they might then try for the more concise, powerful form, which I
> > won't post an example of.
> >
> I'm just a curmudgeon. My example wasn't in Ruby, either. It's really an
> example of how to shoot yourself in the foot *without* Ruby. :)
>
>
> --
> M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC(P)
> http://borasky-research.blo...
>
> If God had meant for carrots to be eaten cooked, He would have given rabbits fire.
>
>
>

Paul Lutus

12/8/2006 7:57:00 AM

0

x1 wrote:

> If you wrapped it with system() in ruby, would it return true or false?

Depends on whether the target directory exists. :)

--
Paul Lutus
http://www.ara...