irb(main):147:0> ["uno","dos","tres"]==%w[uno dos tres]
=> true

easies writing an array



Thread name: "Re: why is the method not found." 
Mail number: 5 
Date: Fri, Dec 05, 2014 
In reply to: Roelof Wobben 
>
> Thanks,
> 
> Can someone explain what the %w does.
> 
> Roelof
> 
> 
> Raj Sahae schreef op 5-12-2014 20:48:
> 
>     The problem is with your test. You are calling it as a class method, not an
>     instance method.
> 
>     Try something like this instead?
> 
>     Test.assert_equals(4", %w(3 4 5).second )
>    
>     
>     Sent from Mailbox
> 
> 
> 
>     On Fri, Dec 5, 2014 at 11:41 AM, Lzaro Armando <lazaro / hcg.sld.cu> wrote:
> 
>         Create new arrays after modify the class
> 
>         irb(main):138:0> class Array
>         irb(main):139:1>
>         irb(main):140:1* def second
>         irb(main):141:2> self.at(1)
>         irb(main):142:2> end
>         irb(main):143:1>
>         irb(main):144:1* end
>         => :second
>         irb(main):145:0> %w[1 2 3].second
>         => "2"
> 
>         already created Arrays should have not your custom methods
> 
> 
> 
>         Thread name: "why is the method not found."
>         Mail number: 1
>         Date: Fri, Dec 05, 2014
>         In reply to: Roelof Wobben
>         >
>         > Hello,
>         >
>         > I try to solve this challenge :
>         >
>         > Define a new instance method on the Array class called second, which
>         returns
>         > the second item in an array (similar to the way .first and .last work
>         in Ruby).
>         >
>         > So I did this :
>         >
>         > class Array
>         >
>         > def second
>         > self.at(1)
>         > end
>         >
>         > end
>         >
>         > With this test :
>         >
>         > Test.assert_equals(4, Array.second([3,4,5]) )
>         >
>         > but as soon as I try the test I see this error:
>         >
>         > ': undefined method `second' for Array:Class (NoMethodError)
>         >
>         > Which I find wierd because I made that method.
>         >
>         > Roelof
>         >
>         >
> 
> 
> 
>