Created
September 10, 2015 09:50
-
-
Save Shinpeim/5bbc424fc4614c456164 to your computer and use it in GitHub Desktop.
This file contains 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
module SerializeForSomeMiddleware | |
module Nyan | |
def serialize_for_middleware | |
# Nyanは aの情報だけでよし | |
{a: @a} | |
end | |
end | |
module Wan | |
def serialize_for_middleware | |
# Wanは b も必要 | |
{a: @a, b: @b} | |
end | |
end | |
end | |
class Nyan | |
def initialize(a, b) | |
@a = a | |
@b = b | |
end | |
end | |
class Wan | |
def initialize(a, b) | |
@a = a | |
@b = b | |
end | |
end | |
def send_to_middleware(x) | |
p x.serialize_for_middleware | |
end | |
nyan = Nyan.new(1,2) | |
wan = Wan.new(3,4) | |
nyan.extend(SerializeForSomeMiddleware::Nyan) | |
wan.extend(SerializeForSomeMiddleware::Wan) | |
send_to_middleware(nyan) # => {a: 1} | |
send_to_middleware(wan) # => {a: 3, b: 4} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment