Ruby 4.0 リファレンスマニュアル

instance method Prism::Comment#slice

slice -> StringRuby 3.4 から[permalink][rdoc][edit]

コメントの文字列そのものを返します。location.slice の短縮形です。

require "prism"

comment = Prism.parse("# hello\n1 + 1").comments.first
p comment.slice # => "# hello"