我需要覆盖 gem“omnicontacts”的方法“email_to_name”,因为它不适用于 ruby 1.8.7。我在此方法中命名正则表达式有错误
lib/omnicontacts/parse_utils.rb:32: undefined (?...) sequence: /(?<first>[a-z|A-Z]+)[\.|_](?<last>[a-z|A-Z]+)/ (SyntaxError)
此方法位于模块 ParseUtils
module OmniContacts
module ParseUtils
def email_to_name username_or_email
...
end
end
end
然后它需要在其他模块中
require "omnicontacts/parse_utils"
require "omnicontacts/middleware/oauth2"
require "json"
module OmniContacts
module Importer
class Gmail < Middleware::OAuth2
include ParseUtils
end
end
end
我试图覆盖这个方法,但它不起作用:
#config/initializer/omnicontacts.rb
require "omnicontacts"
module OmniContacts
module ParseUtils
def email_to_name username_or_email
p "test"
end
end
end
module OmniContacts
module Importer
class Gmail
module ParseUtils
def email_to_name username_or_email
p "test"
end
end
end
end
end
ActionController::Dispatcher.middleware.use OmniContacts::Builder do
importer :gmail, "test", "test", {:redirect_path => "/contacts/gmail/callback"}
importer :yahoo, "test", "test", {:callback_path => '/contacts/yahoo/callback'}
end
我使用 rails 2 和 ruby 1.8.7