=~ Matches a regex against a string and return the offset of the start of
the match or nil.
Below example can illustrate this:
##############################
#!/usr/bin/ruby
a = ['at', 'atx', 'xatx', 'xat', 'xyz']
puts "\nBefore delete_if array is : "
puts a.join("\n")
rgx = Regexp.new(/at/)
puts "\n"
a.each { | x | puts "offset of \'at\' in #{x} is #{rgx =~ x}" }
## delete_if
a.delete_if { | x | rgx =~ x }
puts "\nAfter delete_if array is : "
puts a.join(":")
#############################
----- Original Message -----
From: "Zach Dennis" <zdennis / mktec.com>
To: "ruby-talk ML" <ruby-talk / ruby-lang.org>
Sent: Wednesday, May 26, 2004 10:14 AM
Subject: delete_if woes
> I am having trouble with my delete_if block.
>
> prop_array.delete_if{ |p|
> (p=~/#{attr}/).to_i > 0; }
>
> and i have tried the longer version
>
> prop_array.delete_if{ |p|
> m = (p=~/#{attr}/).to_i
> m > 0; }
>
> and i have tried
>
> prop_array.delete_if{ |p|
> (p=~/#{attr}/) != nil }
>
> It deletes every element, even when m == 0 or m == nil. Any ideas? Thanks,
>
> Zach
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.684 / Virus Database: 446 - Release Date: 5/13/2004
>
>
>