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
> 
>