m.source_location[0] range = node.first_index..node.last_index source = File.binread(path)[range] # => “def foo() bar() end” note: first|last_index are defined here https://github.com/pocke/rinline/blob/2cb6ffb055c619998973f5bd2a349fcb6599e95c/lib/rinline/ext/ast_ext.rb#L144-L161