Class: YardTypes::LiteralType
Overview
A LiteralType constraint is specified by the name of one of YARD's
supported "literals": true, false, nil, void, and self, and
indicates that the object must be exactly one of those values.
However, void and self have no particular meaning: void is typically
used solely to specify that a method returns no meaningful types; and
self is used to specify that a method returns its receiver, generally
to indicate that calls can be chained. All values type check as valid
objects for void and self literals.
Instance Attribute Summary
Attributes inherited from Type
Class Method Summary collapse
-
.names ⇒ Array<String>
The list of supported literal identifiers.
Instance Method Summary collapse
-
#check(obj) ⇒ Boolean
trueif the object is exactlytrue,false, ornil(depending on the value ofname); forvoidandselftypes, this method always returnstrue. -
#description ⇒ String
An English phrase describing this type.
Methods inherited from Type
Constructor Details
This class inherits a constructor from YardTypes::Type
Class Method Details
.names ⇒ Array<String>
Returns the list of supported literal identifiers.
178 179 180 |
# File 'lib/yard_types/types.rb', line 178 def self.names @literal_names ||= %w(true false nil void self) end |
Instance Method Details
#check(obj) ⇒ Boolean
Returns true if the object is exactly true, false, or
nil (depending on the value of name); for void and self
types, this method always returns true.
193 194 195 196 197 198 199 200 201 |
# File 'lib/yard_types/types.rb', line 193 def check(obj) case name when 'true' then obj == true when 'false' then obj == false when 'nil' then obj == nil when 'self', 'void' then true else raise NotImplementedError, "Unsupported literal type: #{name.inspect}" end end |
#description ⇒ String
Returns an English phrase describing this type.
183 184 185 |
# File 'lib/yard_types/types.rb', line 183 def description name end |