Customizing console display of the information within an abstract type instance



This question is probably applicable to multiple packages, but the example I am familiar with and want to somewhat replicate is from the HypothosisTests package.

When an instance of a HypothesisTests.OneSampleTTest is put into the console it displays the name of the test, population details, test summary, and details. The fields are also accessible but are not exactly the same as that list. How does the design of the HypothesisTests abstract type display that information and contain different information?


The custom printing of types is documented here. The key is to overload, ::YourType). In the OneSampleTTest case the relevant definition is

An easy way to find the definition is often to call

julia> t = OneSampleTTest(randn(100), 0.1);

julia> @which show(STDOUT, t)
show(io::IO, test::T) where T<:HypothesisTests.HypothesisTest in HypothesisTests at /Users/andreasnoack/.julia/v0.6/HypothesisTests/src/HypothesisTests.jl:103