[ruby-list:50417] [質問]
From:
Takahiro Yamaguchi <yamataka@...08.itscom.net>
Date:
2016-10-05 15:25:50 UTC
List:
ruby-list #50417
山口と申します。
下記の様な感じで、コードを書こうとしていますが、対処方法が分からず、悩んています。
この様に書けば良いなどのアドバイスをいただければ、幸いです。
NetAudioクラスオブジェクト obj変数作成時に、
モジュール UPnP内 UPnP_Renderクラスオブジェクトを作成。
同時に、
モジュール WebAPI内 WebAPI_AUクラスオブジクトも作成。
両モジュールのクラス関数を、それぞれ、obj変数から
obj=NetAudio.new(device)
obj.upnp_render_play
obj.webapi_au_play
みたいな感じで記述したいのです。
module を使わず、
class NewAudio < UPnP_Render
みたいな感じだと
obj=NetAudio.new(device)
obj.upnp_render_play
で呼出せますが、
class WebAPI_AU を class NewAudioに追加? 派生させる方法が分からず。
自分の思いとしては、
機能毎に、UPnP/WebAPIというそれぞれのmoduleで機能を管理したいので、
moduleを用いて実現できればと思っています。
考え方自体が間違っているかもしれませので、その辺りも含め、ご教示いただければと思います。
以下、不完全なコードになります。
#! /usr/bin/env ruby
module UPnP
class UPnP_Render
def initialize(device)
@device = device
end
def self.from_other(device)
UPnP_Render.new(device)
end
def upnp_render_play
puts "#{__method__} device:#{@device}"
end
end
end
module WebAPI
class WebAPI_AU
def initialize(ip)
@ip = ip
end
def self.from_other(ip)
WebAPI_AU.new(ip)
end
def webapi_au_play
puts "#{__method__} ip:#{@ip}"
end
end
end
class NetAudio
def initialize(device)
UPnP::UPnP_Render.from_other(device[0])
WebAPI::WebAPI_AU.from_other(device[1])
end
end
device=["device info data","aa,bb,cc,dd"]
obj = NetAudio.new(device)
obj.webapi_au_play
obj.upnp_render_play