Ruby 初心者スレッド Part 33
at TECH
61:デフォルトの名無しさん
09/12/08 14:02:01
>>54
class Publisher
def initialize(p)
@text, @from, @to, @path = p[:text], p[:from], p[:to], p[:path]
end
def publish
output = replace(@text, @from, @to)
save(output, @path)
end
def replace(text, from, to); text.gsub(/#{from}/){to}; end
def save(str, path); File.open(path, 'wb'){|f| f.print(str)}; end
end
# Publisher.new(:text => 'ruby大好き!', :from => 'ruby', :to => 'オブジェクト指向スクリプト言語Ruby',
# :path=> 'ruby_love.txt').publish #=> "オブジェクト指向スクリプト言語Ruby大好き!"
これの Publisher#save をテストしたいとかそんなの?
次ページ続きを表示1を表示最新レス表示スレッドの検索類似スレ一覧話題のニュースおまかせリスト▼オプションを表示暇つぶし2ch
5501日前に更新/233 KB
担当:undef