アンチパターンとか,ハマりどころとか
expect(page).to have_content 'hogehoge'
module ApplicationHelper | |
# [example] | |
# simple_table(["A", "B", "C"], [ ["a1", "b1", "c1"], ["a2", "b2", "c2"] ], {:table => { :id => "hoge", :class => "huga"}, :tr => { :class => "piyo"}}) | |
# => | |
# <table id="hoge" class="huga"> | |
# <thead> | |
# <tr class="piyo"> | |
# <th>A</th> | |
# <th>B</th> | |
# <th>C</th> |
ちょっと便利なことだったり,今さら知った恥ずかしいことなど
小文字または`_'で始まる識別子はローカル変数また はメソッド呼び出しです。ローカル変数スコープ(クラス、モジュー ル、メソッド定義の本体)における小文字で始まる識別子への最初 の代入はそのスコープに属するローカル変数の宣言になります。宣 言されていない識別子の参照は引数の無いメソッド呼び出しとみな されます。 ローカル変数のスコープは、((宣言した位置から))その変数が宣 言されたブロック、メソッド定義、またはクラス/モジュール定義 の終りまでです。寿命もそのブロックの終りまで(トップレベルの ローカル変数はプログラムの終了まで)ですが、例外としてブロッ クが手続きオブジェクト化された場合は、そのオブジェクトが消滅 するまで存在します。同じスコープを参照する手続きオブジェクト 間ではローカル変数は共有されます。
require 'chunky_png' | |
# 画像サイズと色の種類は同じと仮定 | |
image1 = ChunkyPNG::Image.from_file('sample1.png') | |
image2 = ChunkyPNG::Image.from_file('sample2.png') | |
xor_image = ChunkyPNG::Image.new(image1.width, image1.height, ChunkyPNG::Color::TRANSPARENT) | |
image1.height.times do |h| | |
image2.width.times do |w| | |
# 0xff透過色を無視 |
require 'active_support' | |
require 'active_support/core_ext/hash/slice' | |
# キーを2つ指定したつもりが単なる文字列になってしまっていた... | |
{ 'key1' => 'hoge', 'key2' => 'fuga', 'key3' => 'piyo' }.slice(*" key1 key2 ") | |
#=> { } |
bundle exec rubocop -D -R | |
# ... | |
629 files inspected, 8475 offenses detected |