Created
February 26, 2009 17:22
-
-
Save ukstudio/70969 to your computer and use it in GitHub Desktop.
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
| # coding: UTF-8 | |
| class Logger | |
| def self.write(out, log) | |
| out.write log | |
| rescue | |
| raise TypeError, "書き込めない何かだよ" | |
| end | |
| end | |
| File.open("hoge", "w") do |f| | |
| Logger.write(f, "log") # ファイルに書き込み | |
| end | |
| # Logger.write(Object.new, "hoge") | |
| class MyClass | |
| def write(num) | |
| raise TypeError, "数値じゃないよ" unless num.is_a? Fixnum | |
| end | |
| end | |
| Logger.write(MyClass.new, "hoge") #=> TypeError, "書き込めない何だよ" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment