Skip to content

Instantly share code, notes, and snippets.

@hadrienblanc
Created August 7, 2018 10:17
Show Gist options
  • Save hadrienblanc/85ce087428dc19fb31a5542648b9c1b0 to your computer and use it in GitHub Desktop.
Save hadrienblanc/85ce087428dc19fb31a5542648b9c1b0 to your computer and use it in GitHub Desktop.
module Miouable
def miouw
puts 'miouw !'
end
end
class CatWithExtend
extend Miouable
end
cat = CatWithExtend.new
cat.miouw
# NoMethodError
# undefined method miouw
CatWithExtend.miouw
# miouw !
module Miouable
def miouw
puts 'miouw !'
end
end
class Cat
include Miouable
end
cat = Cat.new
cat.miouw
# miouw !
Cat.miouw
# NoMethodError
# undefined method miouw for Cat:Class
class Pokemon < ApplicationRecord
scope :active, where(active: true)
scope :red, where(color: 'red')
scope :with_evolution, where.not(next_evolution: nil)
scope :not_savage, where.not(owner_id: 0)
scope :lvl, -> (level) { where(level: level) }
def self.all_active_red_with_evolution_and_not_savage
active.red.with_evolution.not_savage
end
def self.all_red_with_evolution
red.with_evolution
end
def all_red_with_evolution_at_level_max
red.with_evolution.lvl(100)
end
end
class Pokemon < ApplicationRecord
def self.all_active_red_with_evolution_and_not_savage
where(active: true).where(color: 'red').where.not(next_evolution: nil).where.not(owner_id: 0)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment