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.
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.
150 151 152 |
# File 'lib/yard_types/types.rb', line 150 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.
160 161 162 163 164 165 166 167 168 |
# File 'lib/yard_types/types.rb', line 160 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 |