I'm using DataMapper to create rows in MySQL. To make a new row in my "Ryne" table, I do:
a = {:saying, "Ppffftt..!"}
Ryne.create a
So I said to myself, "Since I use this all the time, why not make a more 'slick' method which does this...":
def insertsaying(x)
h = {:saying, x}
Ryne.create h
end
However, my output in IRB for insert saying("Pffffft..")
is:
NoMethodError: undefined method `insertsaying' for main:Object
from (irb):2
The method itself is defined in a .rb file which I am currently requiring in IRB. Aside from the DataMapper.setup
call, the rest of the .rb file looks like this:
DataMapper::Logger.new($stdout, :debug)
dm = DataMapper.setup :default, "mysql://php:phpwebsite@xxx.xxx.xxx.xxx/visit"
dm.resource_naming_convention = DataMapper::NamingConventions::Resource::Underscored
class Ryne
include DataMapper::Resource
is :reflective
reflect /.*/
end
DataMapper.auto_upgrade!
def insertsaying(x)
h = {:saying, x}
Ryne.create h
end
I'm not sure what I am doing wrong however I believe it is a scope issue. Do I need to require something else in the method?