Created
January 30, 2014 15:03
-
-
Save chezou/8710334 to your computer and use it in GitHub Desktop.
classとメソッドの設計は適当ですが、こんなイメージです。
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
| count = 0 | |
| if target_user_ids.empty? | |
| count += Foo.all.count | |
| else | |
| target_user_ids.each do |user_ids| | |
| count += Foo.where(user_id: user_ids).count | |
| 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
| class Foo | |
| def func(arg1, arg2) | |
| return arg1 if arg2.empty? | |
| arg2.each_slice(2).map do |e2| | |
| arg1 & e2 | |
| end.flatten | |
| 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
| require 'spec_helper' | |
| describe 'Foo' do | |
| let(:foo) { Foo.new } | |
| context 'with empty array' do | |
| let(:ary1) { [4,3,2,1] } | |
| let(:ary2) { [] } | |
| it 'returns whole ary1' do | |
| expect(foo.func(ary1, ary2)).to eq(ary1) | |
| end | |
| end | |
| context 'without empty array' do | |
| let(:ary1) { [6,4,3,1] } | |
| let(:ary2) { [1,2,4] } | |
| it 'returns ary1 slected ary2' do | |
| expect(foo.func(ary1, ary2)).to eq([1,4]) | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment