Class: Contracts::Formatters::InspectWrapper
- Inherits:
-
Object
- Object
- Contracts::Formatters::InspectWrapper
- Defined in:
- lib/yard-contracts/formatters.rb
Overview
A wrapper class to produce correct inspect behaviour for different contract values - constants, Class contracts, instance contracts etc.
Instance Method Summary collapse
- #delim(value) ⇒ Object
-
#initialize(value, full = true) ⇒ InspectWrapper
constructor
A new instance of InspectWrapper.
-
#inspect ⇒ Object
Inspect different types of contract values.
-
#to_s ⇒ Object
Eliminates eronious quotes in output that plain inspect includes.
Constructor Details
#initialize(value, full = true) ⇒ InspectWrapper
Returns a new instance of InspectWrapper.
41 42 43 |
# File 'lib/yard-contracts/formatters.rb', line 41 def initialize(value, full = true) @value, @full = value, full end |
Instance Method Details
#delim(value) ⇒ Object
58 59 60 |
# File 'lib/yard-contracts/formatters.rb', line 58 def delim(value) @full ? "(#{value})" : "#{value}" end |
#inspect ⇒ Object
Inspect different types of contract values. Contracts module prefix will be removed from classes. Custom to_s messages will be wrapped in round brackets to differentiate from standard Strings. Primitive values e.g. 42, true, nil will be left alone.
50 51 52 53 54 55 56 |
# File 'lib/yard-contracts/formatters.rb', line 50 def inspect return '' unless full? return @value.inspect if empty_val? return @value.to_s if plain? return delim(@value.to_s) if useful_to_s? @value.inspect.gsub(/^Contracts::/, '') end |
#to_s ⇒ Object
Eliminates eronious quotes in output that plain inspect includes.
63 64 65 |
# File 'lib/yard-contracts/formatters.rb', line 63 def to_s inspect end |