julia> f = x -> 2x
#7 (generic function with 1 method)
julia> m = first(methods(f))
(::getfield(Main, Symbol("##7#8")))(x) in Main at REPL[1]:1
julia> using CodeTracking
julia> whereis(m)[1]
"REPL[1]"
julia> CodeTracking.src_from_file_or_REPL(whereis(m)[1])
"f = x -> 2x"
Edit: CodeTracking basically has this in its README. Using just exported functions, it can instead be written,
julia> definition(String, @which f(1.0))[1]
"f = x -> 2"