arrays.rb5:undefined method 'new' for " Array

16 views
Skip to first unread message

Crippy

unread,
Jul 23, 2008, 11:26:52 AM7/23/08
to Beginning Ruby on Rails E-Commerce
HI I'm an RoR newbie. I'm trying to execute the following code but am
getting the error in the subject line at line five.

Array = ["Hello", "there", "sweetie", 1, 2, 3]
puts Array[0]
puts Array[1]
puts Array.length
Array2 = Array.new
puts array2.length
Array2[0] = "Banana"
Array2[1] = "fish"
puts array2[0] + " " + array2[1]
puts array2.length

Any help would be greatly appreciated!

Jarkko Laine

unread,
Jul 23, 2008, 1:07:28 PM7/23/08
to railsec...@googlegroups.com
Hi Crippy,

On 23.7.2008, at 18.26, Crippy wrote:

>
> HI I'm an RoR newbie. I'm trying to execute the following code but am
> getting the error in the subject line at line five.
>
> Array = ["Hello", "there", "sweetie", 1, 2, 3]

You're basically overwriting the constant Array (which normally points
to the Array class) here. Variable names always start with lowercase,
constants upper. That's why Array doesn't have a method new anymore
after that. Ruby is case-sensitive.

//jarkko

>
> puts Array[0]
> puts Array[1]
> puts Array.length
> Array2 = Array.new
> puts array2.length
> Array2[0] = "Banana"
> Array2[1] = "fish"
> puts array2[0] + " " + array2[1]
> puts array2.length
>
> Any help would be greatly appreciated!
>
> >

--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi


Christopher Yangouyian

unread,
Jul 23, 2008, 1:18:21 PM7/23/08
to railsec...@googlegroups.com
Thank YOU SO MUCH Jarkko!!!
--
-Chris

"Impossible is a word to be found only in the dictionary of fools."-Napoleon Bonaparte
Reply all
Reply to author
Forward
0 new messages