I have a simple class and am transposing a two dimensional array like so:
class Group
attr_accessor :group_array
def initialize
@group_array = []
end
...
def shuffle_groups!
new_groups = group_array.transpose
group_array = new_groups
end
end
However, when I try to set the new group array in one line like so:
def shuffle_groups!
group_array = group_array.transpose
end
I get:
undefined method `transpose' for nil:NilClass
Why does this not work?
Make it clear to the interpreter you are calling the accessor method, and not creating a local variable.
Both of those methods work fine.