This file contains hidden or 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
=begin | |
Представим, что у нас есть некоторый внешний источник, | |
который возвращает нам данные в виде массива хэшей, причем все значения в хэше - строки. | |
Нам нужно написать много разных преобразователей, которые выполняют преобразование | |
переданных данных по заданным правилам. | |
=end | |
# Создайте такой модуль Converter, который позволит создавать такие классы-преобразователи: | |
# Пример преобразователя: |
This file contains hidden or 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
require 'time' | |
module Converter | |
extend Enumerable | |
@@methods = {} | |
def new(*args, &block) | |
initialize(*args, &block) | |
end |
This file contains hidden or 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
# Пример 1 | |
def m | |
a = 1 | |
lambda { a + 1 } | |
end | |
f = m | |
a = 3 | |
f.call #=> ? | |
# Пример 2 |
This file contains hidden or 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
# Пример 1 | |
f = File.open('file.txt', 'w+') | |
f.write('Hello') | |
# Почему выводит "", а не "Hello"? | |
p f.read() #=> "" | |
# Пример 2 | |
file = File.open("file.txt", "r") | |
p file.read #=> "Hello" | |
# Почему второй read снова не выводит "Hello"? |
This file contains hidden or 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
# encoding: utf-8 | |
require 'test_helper' | |
class ProductTest < ActiveSupport::TestCase | |
# Определяем, какую из фикстур загружать для теста | |
# Это будет: test/fixtures/products.yml | |
# fixtures :products - Rails загрузит это по умолчанию | |
# Свойства товара не должны быть пустыми |
This file contains hidden or 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
# encoding: utf-8 | |
class PayerDecorator < Draper::Decorator | |
delegate_all | |
decorates :payer | |
def inn_unique?(inn) | |
Payer.where { (major_requisite.eq 'INN') & (major_requisite_value.eq inn) & (id.not_eq id) }.exists? | |
end | |
end |
This file contains hidden or 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
# This is the content of variable request.env | |
# We get this content in controller: | |
# class BlogsController < ApplicationController | |
# def index | |
# render plain: "Response: #{ YAML::dump(request.env) }" | |
# end | |
# end | |
This file contains hidden or 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
# Copyright 1999-2012 Gentoo Foundation | |
# Distributed under the terms of the GNU General Public License v2 | |
UNICORN_GROUP=${UNICORN_GROUP:-${UNICORN_USER}} | |
UNICORN_CONFIGFILE=${UNICORN_CONFIGFILE:-/etc/unicorn/${RC_SVCNAME}.conf.rb} | |
command=${UNICORN_BINARY:-/usr/bin/unicorn_rails} | |
command_args="${UNICORN_ARGS:--E production} -D -c ${UNICORN_CONFIGFILE}" | |
pidfile=${UNICORN_PIDFILE:-/var/run/${RC_SVCNAME}/unicorn.pid} | |
#start_stop_daemon_args="--user ${UNICORN_USER} --env GEM_HOME=/home/dk/.gem/ruby/1.9" |
This file contains hidden or 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 ServiceBase | |
attr_reader :data | |
class << self | |
def call(data) | |
instance = new(data) | |
instance.call | |
instance | |
end |
This file contains hidden or 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
WITH accessible_users AS ( | |
SELECT DISTINCT public.users.* FROM public.users WHERE | |
public.users.id IN (50034, 33322, 11233) | |
) | |
SELECT | |
1 AS condition, | |
MAX(ac.title) AS accounting_center, -- Центр учета | |
MAX(users.name) AS seller, -- Продавец | |
MAX(clients.id) AS client_id, -- ИД Клиента | |
MAX(clients.title) AS client_title, -- Наименование клиента |
OlderNewer