Skip to content

Instantly share code, notes, and snippets.

@eladmeidar
Created October 14, 2014 18:56
Show Gist options
  • Save eladmeidar/abb93ca884f634ff0132 to your computer and use it in GitHub Desktop.
Save eladmeidar/abb93ca884f634ff0132 to your computer and use it in GitHub Desktop.
module EladPaginator
def self.included(base)
base.class_eval do
include InstanceMethods
extend ClassMethods
end
end
module InstanceMethods
end
module ClassMethods
scope :page, -> (page, per_page) { limit(per_page.to_i).offset((page.to_i - 1) * per_page.to_i)}
end
end
class Product < ActiveRecord::Base
# price_in_cents integer
# shipping_cost_in_cent integer
end
p = Product.new
p.price = 32.1 #=> price_in_cents == 3210
puts p.price #=> 32.1
# define_method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment