Created
October 14, 2014 18:56
-
-
Save eladmeidar/abb93ca884f634ff0132 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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