Peter Hickman
4/8/2008 1:47:00 PM
Peter Bailey wrote:
> Hi,
> I need to cap-and-lowercase words in strings of XML data. Why is this
> happening in this test?
>
> stuff = [ "This", "is", "a", "test" ]
> stuff.collect { |x| puts x.capitalize! }
>
> I get:
>
> nil
> Is
> A
> Test
>
> Program exited with code 0
>
> What's with the "nil?"
>
> Thanks,
> Peter
>
This is because you are using collect where, I suspect, you want to use
each or perhaps drop the puts.
irb(main):004:0> stuff = [ "This", "is", "a", "test" ]
=> ["This", "is", "a", "test"]
irb(main):005:0> stuff.collect{|x| x.capitalize }
=> ["This", "Is", "A", "Test"]
irb(main):006:0>
Maybe that is what you want.