------ art_201_22048713.1201976854042
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Elegant? I don't know, but I kind of like it. :)
"corey".split(//).partition { |x| "aeiouAEIOU"[x] }
returns
[["o", "e"], ["c", "r", "y"]]
irb(main):006:0> "corey haines".split(//).partition { |x| "aeiouAEIOU"[x] }
[["o", "e", "a", "i", "e"], ["c", "r", "y", " ", "h", "n", "s"]]
you might want to skip spaces
-Corey
On Feb 2, 2008 12:38 PM, Robert Dober <robert.dober / gmail.com> wrote:
> >
> > A simple (but I fear not too efficient) way is:
> Not sure if OP excluded non letters from the input
> >
> > class String
> >
> > def vowels
> > gsub(/[^aeiou]/, '')
> > end
> >
> > def consonants
> > gsub(/[aeiou]/, '')
> > end
> >
> > end
> >
> > Stefano
> >
> >
> >
> This shall do it in one run, quite complicated code, interested if
> something more elegant can be found.
> class String
> def v_c
> each_char.inject(["",""]){ |r, c|
> case c
> when /[aeiouy]/i
> [r.first << c, r.last ]
> when /[^a-z]/i
> r
> else
> [r.first, r.last << c ]
> end
> }
> end
> end
>
> HTH
> Robert
>
> --
> http://ruby-smalltalk.blogspot.com/
>
> ---
> Whereof one cannot speak, thereof one must be silent.
> Ludwig Wittgenstein
>
>
--
http://www.coreyhaines.com
The Internet's Premiere source of information about Corey Haines
------ art_201_22048713.1201976854042--