Skip to content

Instantly share code, notes, and snippets.

@demental
Created April 9, 2013 15:38
Show Gist options
  • Save demental/5346723 to your computer and use it in GitHub Desktop.
Save demental/5346723 to your computer and use it in GitHub Desktop.
class Foo
METHODE_NAMES = ['problems', 'maintenances', 'journeys']
class << self
def get_var(name, hsh)
ApiRequest.new(params: {account_id: hsh[:email], vin: hsh[:vin]},
url: "vehicles/#{hsh[:vin]}/#{name}", verb: "get").get
end
METHODE_NAMES.each do name
class_eval <<-METHODS, __FILE__, __LINE__
def self.get_#{name}(hsh = {})
get_var(name, hsh)
end
METHODS
end
end
@mcansky
Copy link

mcansky commented Apr 9, 2013

  class << self
    def get_var(name, hsh)
      ApiRequest.new(params: {account_id: hsh[:email], vin: hsh[:vin]},
        url: "vehicles/#{hsh[:vin]}/#{name}", verb: "get").get
    end
  end
  METHODS_NAMES.each do |meth|
    self.class.class_eval do
      define_method "get_#{meth}" do |hsh|
        get_var(meth, hsh)
      end
    end
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment