7 msg[Challenge] Cookie Monster!
1 msgRuby Quiz 2.0 new location
1 msgHoe and multiple gems

Doing an AND in regexp char class
\ Todd Benson (8 May 2008)
. \ ara.t.howard (8 May 2008)
. . \ Todd Benson (8 May 2008)
. . . \ ara.t.howard (8 May 2008)
. . . . \ Robert Dober (9 May 2008)
. . . \ Joel VanderWerf (9 May 2008)
. . . . \ Todd Benson (9 May 2008)
. . . . . \ Joel VanderWerf (9 May 2008)
. . . . . . \ David A. Black (9 May 2008)
. . . . . . . \ Joel VanderWerf (9 May 2008)
. . . . . . . . \ David A. Black (9 May 2008)
. . . . . . \ Todd Benson (9 May 2008)
. . . . . \ David A. Black (9 May 2008)
. . . . \ 7stud -- (9 May 2008)
. . . . . \ David A. Black (9 May 2008)
. . . . . . \ 7stud -- (9 May 2008)
. . \ Pit Capitain (11 May 2008)
. \ Rick DeNatale (8 May 2008)

2 msgqt ruby gem install on windows xp
1 msgWrite Ruby code sentences
5 msgwired result
11 msgscramble sentence, how to better program?
2 msgwindows prompt, how to write [ ] ?
9 msg[ANN] tagz-4.2.0 - giraffe slayer
1 msgRe: checking connection to server:port [socket]
3 msgHow call scripts in windows using something lik...
2 msgRe: Error when starting the server
3 msgQtRuby: get data from TableWidget
9 msgCompilation error in cont.c
6 msgWriting a SQL Query in Active Record?
5 msgintegers with preceding zero don't return as ex...
12 msgComparing String with Symbol
1 msgAUTO: Joe Grastara is out of the office (return...
6 msgeclipse rdt is painful
Subject:Re: Doing an AND in regexp char class
Group:Ruby-talk
From:Pit Capitain
Date:11 May 2008


 
2008/5/9 ara.t.howard <ara.t.howard>:
> On May 8, 2008, at 3:40 PM, Todd Benson wrote:
>> Using a set perspective, I can do it like this in irb...
>>
>> s1 = "hello there"
>> s2 = "ohi"
>> (s2.unpack('c*') & s1.unpack('c*')).size == s2.size
>>
>> => false
>
> cfp:~ > cat a.rb
> class String
> def all_chars? chars
> tr(chars, '').empty?
> end
> end

Using String#tr is nice, but the result is not what Todd wants:

s1 = "hello there"
s2 = "ohe"

(s2.unpack('c*') & s1.unpack('c*')).size == s2.size
=> true

class String
def all_chars? chars
tr(chars, '').empty?
end
end

s1.all_chars?(s2)
=> false

Like in the regexp examples, you have to switch self and chars:

class String
def all_chars? chars
chars.tr(self, '').empty?
end
end

s1.all_chars?(s2)
=> true

Regards,
Pit



© 2004-2008 readlist.com