Class: Typisch::Type::Time

Inherits:
Constructor::Singleton show all
Defined in:
lib/typisch/datetime.rb

Constant Summary collapse

VALID_IMPLEMENTATION_CLASSES =

You could add your own to the list, if you have some alternative ruby implementation with a Time-like interface which you want to typecheck here.

Maybe allow DateTime too under ruby? its interface is slightly different though. Typisch types are aiming to not be overly coupled to the structure of implementation classes in Ruby though - eg when serializing to JSON we don’t really care about ruby’s DateTime vs Time quirks. So, not sure whether to add DateTime here and pretend its interface is similar enough to that of Time, or just pretend it doesn’t exist.

Or maybe we could just define this as ‘anything which respond_to?(:to_time)’ or similar. Although annoyingly DateTime and Time don’t even have to_time / to_datetime methods to convert between them. Poor stdlib design :(

[::Time]

Constants inherited from Constructor

Constructor::CONSTRUCTOR_TYPE_SUBCLASSES

Instance Attribute Summary

Attributes inherited from Typisch::Type

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Constructor::Singleton

check_subtype, #subexpression_types, #tag, #to_s, top_type

Methods inherited from Constructor

#alternative_types, check_subtype, #check_type, inherited, #tag, top_type, #type_lattice

Methods inherited from Typisch::Type

#<, #<=, #<=>, #==, #===, #>, #>=, #alternative_types, #annotations, #annotations=, #canonicalize!, #excluding_null, #inspect, #recursive?, #subexpression_types, subtype?, #target, #to_s, #to_string

Class Method Details

.tagObject



19
# File 'lib/typisch/datetime.rb', line 19

def self.tag; "Time"; end

Instance Method Details

#shallow_check_type(instance) ⇒ Object



37
38
39
# File 'lib/typisch/datetime.rb', line 37

def shallow_check_type(instance)
  case instance when *VALID_IMPLEMENTATION_CLASSES then true else false end
end