# Wildcard arrays or lists

**URL:** <https://www.ruby-forum.com/t/wildcard-arrays-or-lists/103729>\
**Category:** Ruby\
**Created:** [May 9, 2007, 7:16pm UTC](https://www.ruby-forum.com/t/wildcard-arrays-or-lists/103729 "2007-05-09T19:16:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anansi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9fc348/32.png) [@anansi](https://www.ruby-forum.com/u/anansi)\
**Post date:** [May 9, 2007, 7:16pm UTC](https://www.ruby-forum.com/t/wildcard-arrays-or-lists/103729/1 "2007-05-09T19:16:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anansi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9fc348/32.png) [@anansi](https://www.ruby-forum.com/u/anansi)\
**Post date:** [May 9, 2007, 7:46pm UTC](https://www.ruby-forum.com/t/wildcard-arrays-or-lists/103729/2 "2007-05-09T19:46:06Z")

</div>

On May 9, 10:14 am, anansi [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![anansi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9fc348/32.png) [@anansi](https://www.ruby-forum.com/u/anansi)\
**Post date:** [May 9, 2007, 8:18pm UTC](https://www.ruby-forum.com/t/wildcard-arrays-or-lists/103729/3 "2007-05-09T20:18:34Z")

</div>

> wildcards in an array like
> 
> buff = Array(127.0._._)

There’s a nice ipaddr library in the stdlib which models ip networks and  
addresses, you might want to look at it:

network = IPAddr.new(‘192.168.0.0/16’)  
network.include?(IPAddr.new(‘192.168.0.1’))

- donald
