要約
Prism::ParseResult#comments や Prism?.parse_comments で得られる、ソースコード中のコメントを表す抽象基底クラスです。
実際に生成されるのはサブクラスの Prism::InlineComment(# から始まる通常のコメント)または Prism::EmbDocComment(=begin 〜
=end の埋め込みドキュメント)のどちらかで、このクラス自体のインスタンスが返されることはありません。
[SEE_ALSO] Prism::ParseResult#comments, Prism?.parse_comments
目次
- インスタンスメソッド
インスタンスメソッド
deconstruct_keys(keys) -> HashRuby 3.3 から[permalink][rdoc][edit]-
パターンマッチのハッシュパターン(
case comment; in {location:})で使われます。locationをキーに持つハッシュを返します。- [PARAM]
keys: - 取り出したいキーの配列を指定します。すべて取り出す場合は nil を指定します。
require "prism" comment = Prism.parse("# hello\n1 + 1").comments.first case comment in {location:} p location.slice end # => "# hello" - [PARAM]
location -> Prism::LocationRuby 3.3 から[permalink][rdoc][edit]-
コメントのソースコード上の位置を表す Prism::Location を返します。コメントの文字列そのものは
例location.sliceで取得できます。require "prism" comment = Prism.parse("# hello\n1 + 1").comments.first p comment.location.start_line # => 1 p comment.location.slice # => "# hello" slice -> StringRuby 3.4 から[permalink][rdoc][edit]-
コメントの文字列そのものを返します。
例location.sliceの短縮形です。require "prism" comment = Prism.parse("# hello\n1 + 1").comments.first p comment.slice # => "# hello"