Class: Pione::TupleSpace::TupleType

Inherits:
PioneObject
  • Object
show all
Defined in:
lib/pione/tuple-space/basic-tuple.rb

Overview

TupleType represents tuple's field data type. TupleType has simple and complex form, the latter is consisted by types or-relation. The method +===+ is used by matching field data and type.

Examples:

# create simple type
simple_type = TupleType.new(String)
simple_type === "abc" #=> true
# create complex type
complex_type = TupleType.new(String, Symbol)
complex_type === "abc" #=> true
complex_type === :abc  #=> true

Instance Method Summary collapse

Constructor Details

#initialize(*types) ⇒ TupleType

Creates a tuple field type.

Parameters:

  • types (Array<Object>)

    tuple field types

Raises:

  • (ArgumentError)


26
27
28
29
# File 'lib/pione/tuple-space/basic-tuple.rb', line 26

def initialize(*types)
  raise ArgumentError.new(types) unless types.size > 0
  @types = types
end

Instance Method Details

#===(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



46
47
48
# File 'lib/pione/tuple-space/basic-tuple.rb', line 46

def ===(other)
  @types.find {|t| t === other}
end

#complex?Boolean

Returns true if the type is complex.

Returns:

  • (Boolean)

    true if the type is complex, or false



41
42
43
# File 'lib/pione/tuple-space/basic-tuple.rb', line 41

def complex?
  not(simple?)
end

#simple?Boolean

Returns true if the type is simple.

Returns:

  • (Boolean)

    true if the type is simple, or false



34
35
36
# File 'lib/pione/tuple-space/basic-tuple.rb', line 34

def simple?
  @types.size == 1
end