Class: BELParser::Language::Version2_0::ValueEncodings::Any

Inherits:
Object
  • Object
show all
Defined in:
lib/bel_parser/language/version2_0/value_encodings/any.rb

Overview

The Any value encoding.

Class Method Summary collapse

Class Method Details

.inherited(cls) ⇒ Object

Inherited hook overridden to keep track of descendants. This method is inherited by all descendants.

Parameters:

  • cls (Class)

    the subclass that is inheriting me

See Also:



50
51
52
# File 'lib/bel_parser/language/version2_0/value_encodings/any.rb', line 50

def self.inherited(cls)
  (@subtypes ||= []) << cls
end

.raise_not_implemented(method) ⇒ Object

Raise NotImplementedError for method. Alters the exception backtrace to exclude this method.

Parameters:

  • the (#to_s)

    method name

Raises:

  • (NotImplementedError)

    for method



60
61
62
63
64
65
66
67
68
# File 'lib/bel_parser/language/version2_0/value_encodings/any.rb', line 60

def self.raise_not_implemented(method)
  msg = "#{name} must implement the #{method} method"
  raise NotImplementedError, msg
rescue StandardError
  raise(
    $ERROR_INFO.class,
    $ERROR_INFO.message,
    $ERROR_INFO.backtrace[1..-1])
end

.subtype_of?(other_return_type) ⇒ Boolean

Returns true if I am a subtype of other_return_type; otherwise return false.

Parameters:

  • other_return_type (Class)

    to compare to

Returns:

  • (Boolean)

    true if I am a subtype; false if not



22
23
24
# File 'lib/bel_parser/language/version2_0/value_encodings/any.rb', line 22

def self.subtype_of?(other_return_type)
  self <= other_return_type
end

.subtypesArray<Class>

Retrieve my immediate subtypes.

Returns:

  • (Array<Class>)

    my immediate subtypes



29
30
31
# File 'lib/bel_parser/language/version2_0/value_encodings/any.rb', line 29

def self.subtypes
  (@subtypes ||= []).freeze
end

.to_symObject

Note:

This method should be overridden in subclasses.

Return the Symbol value.



12
13
14
15
# File 'lib/bel_parser/language/version2_0/value_encodings/any.rb', line 12

def self.to_sym
  raise_not_implemented(__method__) if self != Any
  :*
end

.transitive_subtypesArray<Class>

Retrieve my transitive subtypes.

Returns:

  • (Array<Class>)

    my transitive subtypes



36
37
38
39
40
41
42
43
# File 'lib/bel_parser/language/version2_0/value_encodings/any.rb', line 36

def self.transitive_subtypes
  transitive_subtypes =
    (@subtypes ||= []).flat_map do |subtype|
      [subtype, subtype.subtypes]
    end.flatten
  transitive_subtypes << self
  transitive_subtypes.freeze
end