Skip to content

Instantly share code, notes, and snippets.

@a-suenami
Created August 11, 2014 06:36
Show Gist options
  • Select an option

  • Save a-suenami/9eadc3df2bab411dae1b to your computer and use it in GitHub Desktop.

Select an option

Save a-suenami/9eadc3df2bab411dae1b to your computer and use it in GitHub Desktop.
class Zzz
end
module XxxRole
def behavior_as_x
puts "zzz is xxx."
end
end
module YyyRole
def behavior_as_y
puts "zzz is yyy."
end
end
class XContext
def initialize(zzz)
@zzz = zzz
@zzz.extend(XxxRole)
end
def execute
@zzz.behavior_as_x
end
end
class YContext
def initialize(zzz)
@zzz = zzz
@zzz.extend(YyyRole)
end
def execute
@zzz.behavior_as_y
end
end
zzz = Zzz.new
x_context = XContext.new(zzz)
x_context.execute
y_context = YContext.new(zzz)
y_context.execute
@a-suenami
Copy link
Copy Markdown
Author

Result

zzz is xxx.
zzz is yyy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment