I am trying to define an array of arrays as a constant in one of my classes, the code is as follows:
Constant = [[1,2,3,4],
[5,6,7,8]]
When I load the class in irb, I get:
NoMethodError: undefined method `[]' for nil:NilClass
I tried using% w, and everything that was done turned each into a string, so I got "[1,2,3,4]" instead of [1,2,3,4]
How to define an array of arrays as a constant?
Im using ruby 1.8.7.
When I define a constant in IRB, that’s fine, but when I load a class with it, I get an error.
require 'file_with_class.rb'
NoMethodError: undefined method `[]' for nil:NilClass
from ./trainbbcode/tags.rb:2
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from (irb):1
This file is as follows:
class TBBC
Tags = [[/\[b\](.*?)\[\/b\]/,'<strong>\1</strong>',@config[:strong_enabled]],
...
[/\[th\](.*?)\[\/th\]/,'<th>\1</th>',@config[:table_enabled]]]