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
# lib/services/user/signup_service.rb | |
module Services | |
module User | |
class SignUpService | |
attr_reader :publish_statistics_service, | |
:send_email_confirmation_service | |
def initialize( | |
user_publish_statistics_service:, |
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
def parse_arg(arg) | |
a, b, q = arg.split(' ').map(&:to_i) | |
[Range.new(a, b), q] | |
end | |
inputs = [] | |
while arg = STDIN.gets | |
inputs << parse_arg(arg) | |
end |
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
describe :note_for do | |
it 'give notes for the project' do | |
CategoryProject.create(:project => project, | |
:category => category, | |
:description => 'test') | |
params = { :category => category } | |
project.notes.create params.merge(:value => 8) | |
2.times{ project.notes.create params.merge(:value => 3) } |
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
/** | |
Comme nous l'avons vu, il n'y a pas de classe en JavaScript. | |
La notion même d'héritage tel que conçu de manière traditionnelle n'a donc aucun sens. | |
Il existe plusieurs façons de concevoir et mettre en oeuvre l'héritage en JS: | |
* héritage de prototype | |
* héritage classique | |
* copie |
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 Formol | |
class Post < ActiveRecord::Base | |
#Security | |
attr_protected :topic_id, :user_id, :created_by_topic | |
#Virtual attributes | |
attr_accessor :created_by_topic, :quote_id, :register_user_as_subscriber | |
#Default values | |
default_value_for :created_by_topic, false |
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
#lib/active_record/custom_validations.rb | |
module ActiveRecord | |
module CustomValidations | |
def validates_unchanged_value(*attr_names) | |
configuration = { :message => :frozen_attribute } | |
configuration.update(attr_names.extract_options!) | |
configuration[:on] = :update | |
validates_each(attr_names, configuration) do |record, attr_name, value| |
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
class Post < ActiveRecord::Base | |
#... | |
validates_unchanged_value :title, :if => published?, | |
:message => :frozen_attribute_when_published | |
end |
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
a = { :a => '1', :b => '2' } | |
b = a.dup | |
with a do | |
def test_method | |
keys | |
end | |
end | |
a.test_method #=> [:b, :a] |
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
class Object | |
def with(obj, &block) | |
obj.instance_eval &block | |
end | |
end | |
h = { :a => 1, :b => 2 } | |
a = ["a", "b"] | |
with h do |
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
posts = Post.all | |
#renvoie true si ma collection a plusieurs (> 1) élément répondant à la condition passée sous forme de bloc | |
posts.many?(&:published?) #=> true | |
#renvoie true si aucun élément de ma collection ne répond à la condition passée sous forme de bloc | |
posts.none?(&:published?) #=> false | |
#effectue la somme des valeurs renvoyées successivement par un bloc executé sur chaque élément de ma collection | |
posts.sum(&:comments_count) #=> 10 |
NewerOlder