Class: Jubatus::Common::TTuple
- Inherits:
-
Object
- Object
- Jubatus::Common::TTuple
- Defined in:
- lib/jubatus/common/types.rb
Instance Method Summary collapse
- #check_tuple(m) ⇒ Object
- #from_msgpack(m) ⇒ Object
-
#initialize(*types) ⇒ TTuple
constructor
A new instance of TTuple.
- #to_msgpack(m) ⇒ Object
Constructor Details
#initialize(*types) ⇒ TTuple
Returns a new instance of TTuple.
164 165 166 |
# File 'lib/jubatus/common/types.rb', line 164 def initialize(*types) @types = types end |
Instance Method Details
#check_tuple(m) ⇒ Object
168 169 170 171 172 173 |
# File 'lib/jubatus/common/types.rb', line 168 def check_tuple(m) Jubatus::Common.check_type(m, Array) if m.size != @types.size raise TypeError, "size of tuple is %d, but %d is expected: %s" % [m.size, @types.size, m.to_s] end end |
#from_msgpack(m) ⇒ Object
175 176 177 178 179 180 181 182 |
# File 'lib/jubatus/common/types.rb', line 175 def from_msgpack(m) check_tuple(m) tpl = [] @types.zip(m).each do |type, x| tpl << type.from_msgpack(x) end return tpl end |
#to_msgpack(m) ⇒ Object
184 185 186 187 188 189 190 191 |
# File 'lib/jubatus/common/types.rb', line 184 def to_msgpack(m) check_tuple(m) tpl = [] @types.zip(m).each do |type, x| tpl << type.to_msgpack(x) end return tpl end |