Ruby のコードを読んでいると
class Hoge
class << self
def hello
puts 'hello'
end
end
end
require 'bundler/setup' | |
module ExtendModule | |
def foo | |
'foo' | |
end | |
def bar | |
'bar' | |
end |
test_cases = [ | |
%w[ docomo softbank au emobile willcom ], | |
%w[ development production testing staging ], | |
%w[ jp uk de ], | |
] | |
test_cases.first.product(*test_cases[1..-1]) do |carrier, env, region| | |
p carrier: carrier, | |
env: env, | |
region: region | |
end |
Ruby のコードを読んでいると
class Hoge
class << self
def hello
puts 'hello'
end
end
end
Ruby でアプリケーション例外をつくるときの作り方。
begin
# 通常の処理
rescue SomeErrorException => e
# Exception から継承したクラスや StandardError から継承したクラスを指定で受ける
rescue => e # StandardError
# 継承木に StandardError がいるクラスのみひっかかる
else
から自分の環境にあった Ruby の最新版をダウンロード&インストール
これ https://github.com/gocardless/statesman
数多の state machine gem の一つ。
制約フレームワークを書かないと連載させてもらえない Web 雑誌があるようなので、昨日こんなの書いてた。
静的解析もできないし、ドキュメンテーションにも活きないので各方面の識者から怒られそうだが {}
で書けるという見た目の点で許してほしい。
あとはつっこまれるとしたら、継承したときに事前条件、事後条件が強化される/緩和されるのあたり。全部やると大変なんすよ。invariant もないですね (method_added でイベントフックしてすべてのメソッドコールへ prepend かぶせるとかすればできるかな)。
class BeerLover
extend Contracts
attr_accessor :age
Ruby+Rails を始めるのにこの辺をおさえておくといいのでは。 というのを書いていきます。
Ruby
module Ruby | |
module Spock | |
def spec(description, definition = nil, &proc_definition) | |
raise ArgumentError if [ definition, proc_definition ].all? {|d| d.nil? } | |
if definition.nil? | |
spec_runner(description, proc_definition) | |
else | |
spec_runner(description, definition) | |
end | |
end |
class Foo | |
extend Ruby::Spock | |
spec 'maximum of two numbers', ->(*) { | |
expect ->(a, b, c) { [a, b].max == c } | |
where [ | |
# a | b | c | |
[ 1 , 3 , 3 ], | |
[ 7 , 4 , 4 ], | |
[ 0 , 0 , 0 ], |