ruby - undefined method for calling methode in class -
i try call methode check_table_exists check table. methode on module, , dont understand why error .
i know @connexion
mysql2::client instance, doesn't include module sgbd
. dont see how include methode ?
./yamlreadfile.rb:44:in `mysql_connection': undefined method `check_table_exists' #<mysql2::client:0x000000033a7750> (nomethoderror) $load_path << '.' require 'yaml' require 'rubygems' require 'mysql2' require 'creatdatabase' #binding.pry class streammysql include sgbd def mysql_connection(conf) @connexion = mysql2::client.new(:host => conf['ost'], :username => conf['user'], :password => conf['password'], :table => conf['table'], :port => conf['port']) if @connexion puts check_table_exists @connexion.check_table_exists puts "connexion etablie" else puts "error connexion" end rescue mysql2::error => e puts e.errno puts e.error @connexion.close end def read_config_file config = yaml::load_file(file.join(__dir__, 'config.yml')) conf = config['database'] mysql_connection(conf) end end
my module file mehode check_table_exists
module sgbd # class modulecreatedatabase def create_database end def check_table_exists query=("show tables;") end end
it’s unclear why want include module in foreign class, it’s doable:
mysql2::client.include sgbd
the line above should put e. g. before class streammysql
declaration.
Comments
Post a Comment