How do I add a custom method to a Ruby library? -
i'm using restforce
library salesforce queries. queries, following:
client = restforce.new :username => 'user', :password => 'pass', :security_token => 'token', :client_id => 'client_id', :client_secret => 'client_secret'
and call client.query
query salesforce.
i want create custom method called query_with_alises
can call client.query_with_aliases
custom functionality.
how without editing source code of library itself?
you can open class again , add method want.
though exact meaning matter of debate, called monkey-patching. consider monkey-patching overriding/redefining existing methods (which can kinda dangerous), other consider kind of opening existing classes , adding anything, if new methods.
in specific case, can monkey-patch client class restforce that:
class restforce::data::client def query_with_aliases # put code here end end
every other method inside client
keep existing , functioning , add query_with_aliases
.
Comments
Post a Comment