Skip to content

Instantly share code, notes, and snippets.

@ukstudio
Created February 26, 2009 17:22
Show Gist options
  • Select an option

  • Save ukstudio/70969 to your computer and use it in GitHub Desktop.

Select an option

Save ukstudio/70969 to your computer and use it in GitHub Desktop.
# 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