Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

可変引数の実装

  • Loading branch information...
commit 27ef6fa0315f66b35eec4e7caba23e4abda6504a 1 parent b7a4bbf
@ikuru0823 authored
Showing with 16 additions and 5 deletions.
  1. +9 −5 message_filter.rb
  2. +7 −0 message_filter_spec.rb
View
14 message_filter.rb
@@ -1,8 +1,12 @@
class MessageFilter
- def initialize(word)
- @word = word
+ def initialize(*words)
+ @words = words
+ end
+ def detect?(text)
+ @words.each do |w|
+ return true if text.include?(w)
+ end
+ false
end
- def detect?(text)
- text.include?(@word)
- end
end
+
View
7 message_filter_spec.rb
@@ -6,3 +6,10 @@
it{should be_detect('hello from foo')}
it{should_not be_detect('hello,world!')}
end
+
+describe MessageFilter, 'with argument "foo","bar"'do
+ subject{MessageFilter.new('foo','bar')}
+ it {should be_detect('hello from bar')}
+ it{should be_detect('hello from foo')}
+ it{should_not be_detect('hello,world!')}
+end
Please sign in to comment.
Something went wrong with that request. Please try again.