# Filter Array

**URL:** <https://www.ruby-forum.com/t/filter-array/139362>\
**Category:** Rails\
**Created:** [June 3, 2008, 8:59am UTC](https://www.ruby-forum.com/t/filter-array/139362 "2008-06-03T08:59:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hloooi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f17d59/32.png) [@hloooi](https://www.ruby-forum.com/u/hloooi)\
**Post date:** [June 3, 2008, 8:59am UTC](https://www.ruby-forum.com/t/filter-array/139362/1 "2008-06-03T08:59:45Z")

</div>

hihi, can i ask if

how can i filter an Array using ruby?

i have this xml doc with these datas  
a  
**b**  
c

this is my code

invisibility = XPath.first( doc, “//lm:landmark” )  
XPath.each( doc, “//lm:name”) { |element| puts element.text }  
names = XPath.match( doc, “//lm:name” )  
puts names

so how am i gonna filter out the

and it jus shows me a instead of the tags too? pls i really need help  
urgently…

---

<div class="post-metadata">

**Author:** ![hloooi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f17d59/32.png) [@hloooi](https://www.ruby-forum.com/u/hloooi)\
**Post date:** [June 3, 2008, 11:01am UTC](https://www.ruby-forum.com/t/filter-array/139362/2 "2008-06-03T11:01:03Z")

</div>

help me pls ~~~~~~~~

im struggeling…T.T

---

<div class="post-metadata">

**Author:** ![hloooi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f17d59/32.png) [@hloooi](https://www.ruby-forum.com/u/hloooi)\
**Post date:** [June 4, 2008, 3:40am UTC](https://www.ruby-forum.com/t/filter-array/139362/3 "2008-06-04T03:40:25Z")

</div>

wow thx fred for helping me~~~ i got my things work now!!!

really appreciate ur help!!!

if u don mind can pm me ur contact so i can ask u question if i have  
problem??

hehe… if cant its alright~~~

cause im really new to ruby but need to start creating application using  
these ruby… ehhe…

anyway thx alot

---

<div class="post-metadata">

**Author:** ![hloooi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f17d59/32.png) [@hloooi](https://www.ruby-forum.com/u/hloooi)\
**Post date:** [June 3, 2008, 11:28am UTC](https://www.ruby-forum.com/t/filter-array/139362/4 "2008-06-03T11:28:29Z")

</div>

On Jun 3, 10:01 am, loki ja [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> invisibility = XPath.first( doc, “//lm:landmark” )  
> names = XPath.each( doc, “//lm:name”) { |element| puts element.text }

You probably meant something like  
names = []  
XPath.each ( doc, “//lm:name”) { |element| names \<\< element.text }

In your code the block does nothing apart from output the text - the  
return value is just the collection iterated over.

Fred

---

<div class="post-metadata">

**Author:** ![hloooi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f17d59/32.png) [@hloooi](https://www.ruby-forum.com/u/hloooi)\
**Post date:** [June 3, 2008, 11:01am UTC](https://www.ruby-forum.com/t/filter-array/139362/5 "2008-06-03T11:01:50Z")

</div>

invisibility = XPath.first( doc, “//lm:landmark” )  
names = XPath.each( doc, “//lm:name”) { |element| puts element.text }

puts names

jus split the string is enough… how…~~~

---

<div class="post-metadata">

**Author:** ![hloooi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f17d59/32.png) [@hloooi](https://www.ruby-forum.com/u/hloooi)\
**Post date:** [June 4, 2008, 3:59am UTC](https://www.ruby-forum.com/t/filter-array/139362/6 "2008-06-04T03:59:17Z")

</div>

it’s better posting on the mailing list because if someone else has a  
similar problem, they may google it and find it.  
On Wed, Jun 4, 2008 at 11:10 AM, loki ja  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> cause im really new to ruby but need to start creating application using  
> these ruby… ehhe…
> 
> ## anyway thx alot
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Appreciated my help?  
Recommend me on Working With Rails  
[http://workingwithrails.com/person/11030-ryan-bigg](http://workingwithrails.com/person/11030-ryan-bigg)
