Created
May 19, 2010 01:49
-
-
Save tobynet/405849 to your computer and use it in GitHub Desktop.
Rubyでaliasを使った特異メソッドの上書き方法
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
#!ruby -Ku | |
# override_method/stdout_hook_singleton_method.rb | |
$KCODE = 'u' | |
# sample of override singleton method | |
require "kconv" | |
$stdout.sync = true | |
class << $stdout | |
alias :old_write_for_sjis_filter :write | |
def write(str) | |
#old_write_for_sjis_filter str.to_s.kconv(Kconv::SJIS, Kconv::UTF8) | |
#old_write_for_sjis_filter str.to_s.tosjis | |
# change to sjis AS IS | |
old_write_for_sjis_filter NKF.nkf('-sxm0', str.to_s) | |
end | |
end | |
puts "表が怖い噂のソフト" | |
puts "UTF-8→SJISフックキタ━(゚∀゚)━ !!" | |
puts "▶✉✦❤➡✖✔✸●■◢ ◣ ◤ ◥◧ ◨ ◩ ◪▲▼▶◀♂ ♀ ♪ ♫ ☼" | |
puts "テストまげもりまげもり" | |
puts "お前の脳天などこのテポドンキックで粉々に粉砕してやるわアアア~~~~~~!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
解説元サイト: Ruby/特異メソッドの上書きと退避 - TOBY SOFT wiki