[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Match string from possible strings

John Butler

4/11/2008 10:06:00 AM

Hi,

Ive looked about and found some ways to do this but there must be a 1
line quick way in ruby using regular expressions or something.

Basically i have a string "Test" and i want to see if it matches 3
constants that i have defined. If it does then i want to go route a,
and if it doesnt i want to go route b, so:

If "Test" (matches either of the following) string1, string2, string3
route a
else
route b
end

Anyone know the quick way?

JB
--
Posted via http://www.ruby-....

7 Answers

7stud --

4/11/2008 10:21:00 AM

0

John Butler wrote:
> Hi,
> If "Test" (matches either of the following) string1, string2, string3
> route a
> else
> route b
> end
>
> Anyone know the quick way?
>
> JB

if [string1, string2, string3].include?('Test')
--
Posted via http://www.ruby-....

elof

4/11/2008 10:21:00 AM

0


Hi

On Fri, 11 Apr 2008 19:05:47 +0900, John Butler <johnnybutler7@gmail.com>
wrote:
> Hi,
>
> Ive looked about and found some ways to do this but there must be a 1
> line quick way in ruby using regular expressions or something.
>
> Basically i have a string "Test" and i want to see if it matches 3
> constants that i have defined. If it does then i want to go route a,
> and if it doesnt i want to go route b, so:
>
> If "Test" (matches either of the following) string1, string2, string3
> route a
> else
> route b
> end
>
> Anyone know the quick way?

This looks like a potential Ruby Quiz challenge.

Kristian


ThoML

4/11/2008 11:07:00 AM

0

> If "Test" (matches either of the following) string1, string2, string3

Does "match" mean "is equal" or "match a regexp"?

If it is "is equal"
- use include?
- use case

if it means regexp matching
- use [...].grep.empty? for no match
- build a single regexp to match all 3 constants and use =~
- ...

Tim Hunter

4/11/2008 11:17:00 AM

0

John Butler wrote:
> Hi,
>
> Ive looked about and found some ways to do this but there must be a 1
> line quick way in ruby using regular expressions or something.
>
> Basically i have a string "Test" and i want to see if it matches 3
> constants that i have defined. If it does then i want to go route a,
> and if it doesnt i want to go route b, so:
>
> If "Test" (matches either of the following) string1, string2, string3
> route a
> else
> route b
> end
>
> Anyone know the quick way?
>
> JB

What's wrong with

if string1 == "Test" || string2 == "Test" || string3 == "Test"


--
RMagick: http://rmagick.ruby...
RMagick 2: http://rmagick.ruby...rmagick2.html

Park Heesob

4/11/2008 12:42:00 PM

0

SGksDQotLS0tLSBPcmlnaW5hbCBNZXNzYWdlIC0tLS0tIA0KRnJvbTogIkpvaG4gQnV0bGVyIiA8
am9obm55YnV0bGVyN0BnbWFpbC5jb20+DQpOZXdzZ3JvdXBzOiBjb21wLmxhbmcucnVieQ0KVG86
ICJydWJ5LXRhbGsgTUwiIDxydWJ5LXRhbGtAcnVieS1sYW5nLm9yZz4NClNlbnQ6IEZyaWRheSwg
QXByaWwgMTEsIDIwMDggNzowNSBQTQ0KU3ViamVjdDogTWF0Y2ggc3RyaW5nIGZyb20gcG9zc2li
bGUgc3RyaW5ncw0KDQoNCj4gSGksDQo+IA0KPiBJdmUgbG9va2VkIGFib3V0IGFuZCBmb3VuZCBz
b21lIHdheXMgdG8gZG8gdGhpcyBidXQgdGhlcmUgbXVzdCBiZSBhIDENCj4gbGluZSBxdWljayB3
YXkgaW4gcnVieSB1c2luZyByZWd1bGFyIGV4cHJlc3Npb25zIG9yIHNvbWV0aGluZy4NCj4gDQo+
IEJhc2ljYWxseSBpIGhhdmUgYSBzdHJpbmcgIlRlc3QiIGFuZCBpIHdhbnQgdG8gc2VlIGlmIGl0
IG1hdGNoZXMgMw0KPiBjb25zdGFudHMgdGhhdCBpIGhhdmUgZGVmaW5lZC4gIElmIGl0IGRvZXMg
dGhlbiBpIHdhbnQgdG8gZ28gcm91dGUgYSwNCj4gYW5kIGlmIGl0IGRvZXNudCBpIHdhbnQgdG8g
Z28gcm91dGUgYiwgIHNvOg0KPiANCj4gSWYgIlRlc3QiIChtYXRjaGVzIGVpdGhlciBvZiB0aGUg
Zm9sbG93aW5nKSBzdHJpbmcxLCBzdHJpbmcyLCBzdHJpbmczDQo+IHJvdXRlIGENCj4gZWxzZQ0K
PiByb3V0ZSBiDQo+IGVuZA0KPiANCj4gQW55b25lIGtub3cgdGhlIHF1aWNrIHdheT8NCj4gDQo+
IEpCDQoNCklzIHRoaXMgd2hhdCB5b3Ugd2FudD8NCg0KaWYgW3N0cmluZzEsc3RyaW5nMixzdHJp
bmczXS5pbmNsdWRlPygiVGVzdCIpDQouLi4NCg0KUmVnYXJkcywNClBhcmsgSGVlc29iDQo=


John Butler

4/11/2008 12:44:00 PM

0

Park Heesob wrote:
> Hi,
> ----- Original Message -----
> From: "John Butler" <johnnybutler7@gmail.com>
> Newsgroups: comp.lang.ruby
> To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
> Sent: Friday, April 11, 2008 7:05 PM
> Subject: Match string from possible strings
>
>
>> route a
>> else
>> route b
>> end
>>
>> Anyone know the quick way?
>>
>> JB
>
> Is this what you want?
>
> if [string1,string2,string3].include?("Test")
> ...
>
> Regards,
> Park Heesob

Yes,

This is what i have used,

thanks

JB

--
Posted via http://www.ruby-....

Jasmine Swallow

4/11/2008 1:04:00 PM

0

Hi,

I am currently looking for Ruby on Rails Web Developers for a permanent
and a contract opportunity based in London. If you are interested in
this opportunity, please feel free to contact me. Alternatively, if this
is not of interest to you but you have any friends or colleagues who are
looking for either Ruby on Rails work or indeed any other roles within
the IT field, please feel free to pass their details on to me or pass my
details to them.

Kind Regards,
Jasmine
j.swallow@preferred-it.com
--
Posted via http://www.ruby-....