Created
September 10, 2015 09:41
-
-
Save Shinpeim/7bda0607c065e4fcdf6b 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 | |
include SerializeForSomeMiddleware::Nyan | |
def initialize(a, b) | |
@a = a | |
@b = b | |
end | |
end | |
class Wan | |
include SerializeForSomeMiddleware::Wan | |
def initialize(a, b) | |
@a = a | |
@b = b | |
end | |
end | |
def send_to_middleware(x) | |
p x.serialize_for_middleware | |
end | |
send_to_middleware(Nyan.new(1,2)) # => {a: 1} | |
send_to_middleware(Wan.new(3,4)) # => {a: 3, b: 4} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment