123456789_123456789_123456789_123456789_123456789_

Module: Concurrent::Actor::TypeCheck

Overview

taken from Algebrick supplies type-checking helpers whenever included

Class Method Summary

Instance Method Summary

Class Method Details

.error(value, message, types) (private)

Raises:

  • (TypeError)
[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/actor/type_check.rb', line 41

def self.error(value, message, types)
  raise TypeError,
        "Value (#{value.class}) '#{value}' #{message} any of: #{types.join('; ')}."
end

Instance Method Details

Child!(value, *types)

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/actor/type_check.rb', line 33

def Child!(value, *types)
  Child?(value, *types) or
      TypeCheck.error(value, 'is not child', types)
  value
end

Child?(value, *types) ⇒ Boolean

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/actor/type_check.rb', line 28

def Child?(value, *types)
  Type?(value, Class) &&
      types.any? { |t| value <= t }
end

Match!(value, *types)

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/actor/type_check.rb', line 22

def Match!(value, *types)
  Match?(value, *types) or
      TypeCheck.error(value, 'is not matching', types)
  value
end

Match?(value, *types) ⇒ Boolean

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/actor/type_check.rb', line 18

def Match?(value, *types)
  types.any? { |t| t === value }
end

Type!(value, *types)

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/actor/type_check.rb', line 12

def Type!(value, *types)
  Type?(value, *types) or
      TypeCheck.error(value, 'is not', types)
  value
end

Type?(value, *types) ⇒ Boolean

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/actor/type_check.rb', line 8

def Type?(value, *types)
  types.any? { |t| value.is_a? t }
end