Skip to content

Instantly share code, notes, and snippets.

Singleton パターンを用いると、そのクラスのインスタンスが1つしか生成されないことを保証することができる。 ロケールやLook&Feelなど、絶対にアプリケーション全体で統一しなければならない仕組みの実装に使用される
@kasei-san
kasei-san / file0.txt
Created July 28, 2014 22:34
ActiveSupport::Concern と、Module#concerning ref: http://qiita.com/kasei-san/items/c016c626836da09a5a70
関心事、関連、利害関係 など
require "open-uri"
class Titles
include Enumerable
def initialize
@urls = []
end
def <<(url)
@urls << url
# ファイルを生成して、upload するという流れ
class FileUploader # Client
def initialize(factory)
@file_maker = factory.file_maker
@uploader = factory.uploader
end
def make_flie(items)
@file = file_maker.make(item)
end
アルゴリズムを実行時に選択することができるデザインパターンである。
引数 klass で指定したクラスだけに対して、ブロックで指定した機能を提供で きるモジュールを定義します。定義した機能は Module#refine を使用せずに直 接 klass に対して変更を行う場合と異なり、限られた範囲のみ有効にできます。 そのため、既存の機能を局所的に修正したい場合などに用いる事ができます。
class StringListerViewer
attr_reader :items, :type
def initialize(items, type)
@items = items
@type = type
end
def string_lister(items)
Object.const_get("#{type.to_s.capitalize}StringLister").new(items)
end
@kasei-san
kasei-san / gist:10003192
Last active August 29, 2015 13:58
スレッド操作いろいろ
#include <stdio.h>
#include <pthread.h>
#include <iostream>
class LedMatrix {
private:
pthread_t thread; // スレッドハンドラ
pthread_mutex_t mutex; // ミューテックス(排他処理で優先権を決めるやつ)
int data;
public: