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
require 'ftpd' | |
class Driver | |
def initialize(temp_dir) | |
@temp_dir = temp_dir | |
end | |
def authenticate(user, password) | |
true | |
end | |
def file_system(user) |
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
require 'mysql2' | |
client = Mysql2::Client.new(:host => "localhost", :username => "root", :password => "password", :database => "ar_sample") | |
results = client.query('DROP TABLE if exists pet') | |
results = client.query('CREATE TABLE pet (id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, name CHAR(30), owner_name CHAR(20), age SMALLINT(6));') | |
class String | |
def to_sql; "\"#{self.to_s}\""; end | |
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
# wrap_method оборачивает вызовы методов вызовами before- и after-методов | |
# Возможно множественная обертка, в ходе которой образуется method-chain | |
module Wrappable | |
class WrapperOptions | |
attr_reader :before_callback, :after_callback | |
def initialize(&block) | |
instance_eval(&block) | |
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
# Представим, что у нас есть некоторый внешний источник, который возвращает нам данные в виде массива хэшей. | |
# Причём все значения в хэшах передаются как строки. Создайте такой универсальный класс Storage, который позволит | |
# создавать классы преобразователи: | |
require 'time' | |
class Storage | |
def self.attrb(attribute_name, attribute_accessor = nil, &process_proc) | |
raise ArgumentError if attribute_name.nil? |
NewerOlder