Skip to content

Instantly share code, notes, and snippets.

@atton
Last active August 29, 2015 14:12
Show Gist options
  • Save atton/c5d1f6eb2a2b803ee3cc to your computer and use it in GitHub Desktop.
Save atton/c5d1f6eb2a2b803ee3cc to your computer and use it in GitHub Desktop.
sinple emluate scoped module by refinements
#!/usr/bin/env ruby
class ActiveRecord
def save
puts 'ActiveRecord'
end
end
#!/usr/bin/env ruby
module Hoge
refine ActiveRecord do
def nya
save
puts 'nya'
end
def save
puts 'hoge save'
end
end
end
#!/usr/bin/env ruby
require './ar'
require './hoge'
class A < ActiveRecord
end
#!/usr/bin/env ruby
require './model'
A.new.save # => ActiveRecord
A.new.nya # nya is undefined
#!/usr/bin/env ruby
require './model'
using Hoge
A.new.save # hoge
A.new.nya # hoge, nya
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment