error: undefined method

S

Siratinee Sukachai

I create a method named splitDot which is spliting a dot "."
Inside a class, I call that method but I got the error.

This is the full error:

app/controllers/convert_to_yaml.rb:14: undefined method `splitDot' for
ConvertToYaml:Class (NoMethodError)
from app/controllers/convert_to_yaml.rb:13:in `each'
from app/controllers/convert_to_yaml.rb:13

My method:

private

def splitDot(s)
return s.split('.')
end

And I call the method like this:

text.each{|t|
array = splitDot(t)
}

Any suggestions?
 
B

Brian Candler

Siratinee Sukachai wrote in post #994228:
Any suggestions?

Yes - make a standalone minimal program which demonstrates the problem.

You're showing your code out of context - we can't see what class each
method is defined in. If you can make a simple program which
demonstrates the problem, then we can run it, and can debug it for you -
although more than likely you'll find the problem yourself as part of
the process of boiling it down to a simple case.

Right now, the code you've posted isn't even valid Ruby:

class ConvertToYaml
{
...
} # wrong

class ConvertToYaml
...
end # right
 
S

Siratinee Sukachai

Yeah, I'm sorry. Actually, I mean the code is

class ConvertToYaml
...
text.each{|t|
array = splitDot(t)
}
...

private

def splitDot(s)
return s.split('.')
end
end
 
G

Gunther Diemant

It seems that you call splitDot as class method and not inside another
instance method. But you define splitDot to be an instance method.

Try
def self.splitDot(s)
s.split '.'
end

PS: Maybe even better: remove the splitDot method completly and use
the split method directly:
text.each { |t| array = t.split('.') }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top