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
# 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
# Пример 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
# Пример 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
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
=begin | |
Представим, что у нас есть некоторый внешний источник, | |
который возвращает нам данные в виде массива хэшей, причем все значения в хэше - строки. | |
Нам нужно написать много разных преобразователей, которые выполняют преобразование | |
переданных данных по заданным правилам. | |
=end | |
# Создайте такой модуль Converter, который позволит создавать такие классы-преобразователи: | |
# Пример преобразователя: |
NewerOlder