Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > wildcard arrays or lists

Reply
Thread Tools

wildcard arrays or lists

 
 
anansi
Guest
Posts: n/a
 
      05-09-2007
hi ,
I wondered if it is possible to tell ruby to accept wildcards in arrays
or lists. I have a function which relys on .each and accepts arrays and
lists of IP's. Is it possible to use wildcards in an array like

buff = Array(127.0.*.*)

of couse this is not working but is there any way to do this? Or is my
only option to fill the array "by hand" with a loop with every single IP?

--
greets

(
)
(
/\ .-"""-. /\
//\\/ ,,, \//\\
|/\| ,;;;;;, |/\|
//\\\;-"""-;///\\
// \/ . \/ \\
(| ,-_| \ | / |_-, |)
//`__\.-.-./__`\\
// /.-(() ())-.\ \\
(\ |) '---' (| /)
` (| |) `
jgs \) (/


one must still have chaos in oneself to be able to give birth to a
dancing star
 
Reply With Quote
 
 
 
 
james.d.masters@gmail.com
Guest
Posts: n/a
 
      05-09-2007
On May 9, 10:14 am, anansi <(E-Mail Removed)> wrote:
> I wondered if it is possible to tell ruby to accept wildcards in arrays
> or lists. I have a function which relys on .each and accepts arrays and
> lists of IP's. Is it possible to use wildcards in an array like
>
> buff = Array(127.0.*.*)
>
> of couse this is not working but is there any way to do this? Or is my
> only option to fill the array "by hand" with a loop with every single IP?


The problem is what do you mean by "*"? Is it limited to numbers or
can letters be included? Since you're specifying an IP address in
this case, you are probably limiting it to a finite set of positive
integers. You could use a number of Ruby iterators to fill in all
possible combinations (Array#upto immediately comes to mind; ie:
0.upto(127) {|i| buff.push "127.0.#{i}.0"} - of course you'll need to
have two loops to fill in the two last numbers).

But I'm curious as to why you want to do this in the first place. I'm
thinking that a regular expression might be more suitable; however, I
can't be sure without more information.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wildcard String Comparisons: Set Pattern to a Wildcard Source chaoticcranium@gmail.com Python 7 10-05-2010 09:26 PM
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
List of lists of lists of lists... =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==?= Python 5 05-15-2006 11:47 AM
lists of lists Jon Slaughter C++ 4 12-13-2004 06:28 PM
Sorting lists of lists... JustSomeGuy C++ 0 06-17-2004 05:44 PM



Advertisments