Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tobynet/405853 to your computer and use it in GitHub Desktop.
Save tobynet/405853 to your computer and use it in GitHub Desktop.
RailsのActiveSupportのalias_method_chainを使ったRubyでの特異メソッドの上書き方法
#!ruby -Ku
# override_method/stdout_hook_singleton_method_with_activesupport.rb
$KCODE = 'u'
# sample of override singleton method with active_supportlike a Rails
# alias_method_chain (ActiveSupport::CoreExtensions::Module) - APIdock
# http://apidock.com/rails/ActiveSupport/CoreExtensions/Module/alias_method_chain
require "rubygems"
require "active_support"
require "kconv"
$stdout.sync = true
class << $stdout
def write_with_for_sjis_filter(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
write_without_for_sjis_filter NKF.nkf('-sxm0', str.to_s)
end
# same as...
# alias_method :write_without_for_sjis_filter, :write
# alias_method :write, :write_with_for_sjis_filter
alias_method_chain :write, :for_sjis_filter
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