Error: undefined method

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:ineach’
from app/controllers/convert_to_yaml.rb:13

I do like this

class ConvertToYaml
{

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

private

def splitDot(s)
return s.split(’.’)
end
}

Any suggestions?

Siratinee S. 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

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

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(’.’) }

2011/4/21, Siratinee S. [email protected]:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs