Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
refinements w/ block
class A
def say
puts "A"
end
end
module B
def self.role(klass, &block)
ref = refine(klass) { }
ref.module_eval(&block)
end
role A do
def say
puts "B"
end
end
end
class C
using B
def say
A.new.say
end
end
A.new.say # => A
C.new.say # => B
@rosylilly

This comment has been minimized.

Copy link
Owner Author

commented Jan 5, 2014

  1. refine(klass) { } で空のブロックを渡しているのはブロックなしで実行できないため
  2. refine(klass, &block) は処理系で規制されておりつかえない
  3. alias_method でも十分にたような別名が使える
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.