Three_ways

apa is a dummy-class with a method :add.
The gem ‘method_source’ is required.

# first
apa.method(:add).source.each_line {|ln|
  @ind ||= ln[/^(\s*)/].size
  puts ln[@ind...]
}


# second
ar = apa.method(:add).source.lines
indent = ar[0][/^(\s*)/].size
ar.each {|ln| puts ln[indent..] }


# third
en = apa.method(:add).source.split("\n").to_enum
ind = en.peek[/^(\s*)/].size
loop do; puts en.next[ind..]; end

The first version is using ||= to get the indentation of the first line.

The second is creating an array of lines and checks the first item for indentation.

The third is using enumerator and peeks at the first line to get indentation.