Module: YardTypes
- Extended by:
- YardTypes
- Included in:
- YardTypes
- Defined in:
- lib/yard_types.rb,
lib/yard_types/types.rb,
lib/yard_types/parser.rb,
lib/yard_types/version.rb
Overview
YardTypes provides a parser for YARD type descriptions, and testing whether objects are of the specified types.
Defined Under Namespace
Modules: OrList Classes: CollectionType, DuckType, Failure, HashType, KindType, LiteralType, Parser, Result, Success, TupleType, Type, TypeConstraint
Constant Summary collapse
- VERSION =
"0.2.0"
Instance Method Summary collapse
-
#check(type, obj) ⇒ Result
Parses a type identifier with #parse, then validates that the given
objsatisfies the type constraint. -
#parse(type) ⇒ TypeConstraint
Parse a type string using the Parser, and return a TypeConstraint instance representing the described type.
Instance Method Details
#check(type, obj) ⇒ Result
Parses a type identifier with #parse, then validates that the
given obj satisfies the type constraint.
60 61 62 63 64 65 66 67 |
# File 'lib/yard_types.rb', line 60 def check(type, obj) constraint = parse(type) if constraint.check(obj) Success.new else Failure.new end end |
#parse(type) ⇒ TypeConstraint
Parse a type string using the Parser, and return a TypeConstraint instance representing the described type.
49 50 51 52 |
# File 'lib/yard_types.rb', line 49 def parse(type) type = type.join(', ') if type.respond_to?(:join) Parser.parse(type) end |