NoMethodError, most likely foolish...

A

Adam Cohen

So I am fairly new to ruby and I'm using the language to work on a new
project. The details of the project however are not relevant to this
post, but some of the code is.

Long story short, I have a big case statement that will execute
different methods depending on input (its a command line system im
building for sometihng) and the case will call my method version_info?
by using the call self.version_info? however I then get this error
instead of the proper output.

secretproject.rb:51: undefined method `version_info?' for main:Object
(NoMethodError)


my method looks like this

def version_info?
puts 'secretproject runtime version ' + version.to_s
puts 'written and maintained: Adam Ross Cohen'
puts 'math genius: Evan Penn'
puts 'thanks for playing.'
end

I dont understand why the object doesn't contain the method, however I
have a hunch... my ruby file isn't a class, its just a file with methods
in it, however as I understand it I should still be able to call the
method because it makes the object when it runs the file.

please let me know if you can correct my (most likely foolish) mistake.
thanks in advance, A. Ross Cohen
 
G

Greg Willits

Adam said:
by using the call self.version_info? however I then get this error
instead of the proper output.

my method looks like this

def version_info?
puts 'secretproject runtime version ' + version.to_s
puts 'written and maintained: Adam Ross Cohen'
puts 'math genius: Evan Penn'
puts 'thanks for playing.'
end


Don't use self.version_info? -- just call version_info?

A file with just this in it works fine:

#---------
def who_am_i?
puts "I Be Ruby"
end

who_am_i?
#---------

-- greg willits
 

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,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top