2016-07-25 253 views
-1

我嘗試調用我的方法check_table_exists檢查我的表。這種方法在我的模塊上,我不明白爲什麼我得到這個錯誤。未定義的方法調用方法

我知道@connexion是一個Mysql2 :: Client實例,它不包含模塊Sgbd。但我不知道如何包含我的方法?

./yamlReadFile.rb:44:in `mysql_connection': undefined method `check_table_exists' for #<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 

我與mehode模塊文件check_table_exists

module Sgbd 

# class ModuleCreateDatabase 

    def create_database 

    end 

    def check_table_exists 
     query=("SHOW TABLES;") 
    end 

end 

回答

0

爲什麼你想在國外一流的模塊目前還不清楚,但它是可行的:

Mysql2::Client.include Sgbd 

的上面的行應該放在e。 G。在class StreamMysql聲明之前。

+0

我想要一個類的連接,併爲任務模塊像(選擇,更新,創建等... – Oliver

相關問題