# NoMethodError (...occurred while evaluating nil.split)

**URL:** <https://www.ruby-forum.com/t/nomethoderror-occurred-while-evaluating-nil-split/132221>\
**Category:** Rails\
**Created:** [March 18, 2008, 12:38am UTC](https://www.ruby-forum.com/t/nomethoderror-occurred-while-evaluating-nil-split/132221 "2008-03-18T00:38:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![immortalnights](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/7cd45c/32.png) [@immortalnights](https://www.ruby-forum.com/u/immortalnights)\
**Post date:** [March 18, 2008, 12:38am UTC](https://www.ruby-forum.com/t/nomethoderror-occurred-while-evaluating-nil-split/132221/1 "2008-03-18T00:38:11Z")

</div>

I am getting a NoMethodError, with the following decription:

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.split

The error is raised on function call line of the ‘.html.erb’ file.

The function is present in the relevant ‘helper.rb’ file and contains  
the following:

```auto
def splitBonusUnit(data)
  @returnValue = @data.split(/ /)
  return @returnValue
end
```

The ‘data’ value passed into the function is confirmed to be “2 3”; when  
the code @data.split(/ /) is entered into the Ruby shell it works and  
expected and [“2”, “3”] is returned.

Why is this not working correctly when put within the Ruby on Rails web  
pages? If I take the ‘split’ command out of the helper function, it also  
works correctly.

My understanding of Ruby and Ruby on Rails is limited, as is likely  
obvious, so although I have found a way around it, I would appreciate a  
pointer to why it does what it does.

Thank you.

---

<div class="post-metadata">

**Author:** ![immortalnights](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/7cd45c/32.png) [@immortalnights](https://www.ruby-forum.com/u/immortalnights)\
**Post date:** [March 18, 2008, 1:01am UTC](https://www.ruby-forum.com/t/nomethoderror-occurred-while-evaluating-nil-split/132221/2 "2008-03-18T01:01:00Z")

</div>

Immortal Nights wrote:

> def splitBonusUnit(data)  
> @returnValue = @data.split(/ /)

Your parameter is “data”, but you are operating on “@data”. Make that:

@returnValue = data.split(/ /)

Also, if you are not referring to @returnValue elsewhere, then there is  
no need to make that an instance variable…

---

<div class="post-metadata">

**Author:** ![immortalnights](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/7cd45c/32.png) [@immortalnights](https://www.ruby-forum.com/u/immortalnights)\
**Post date:** [March 18, 2008, 1:10am UTC](https://www.ruby-forum.com/t/nomethoderror-occurred-while-evaluating-nil-split/132221/3 "2008-03-18T01:10:15Z")

</div>

Well; something told me it would be rather simple. Yet, I tried so many  
things, but that.

Thank you.

> Also, if you are not referring to @returnValue elsewhere, then there is  
> no need to make that an instance variable…

I agree, the variable was only created just on the off chance return on  
the split command was the issue.

Again, thank you for your prompt reply.
