Class: SyntaxTree::AssocSplat

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.rb

Overview

AssocSplat represents double-splatting a value into a hash (either a hash literal or a bare hash in a method call).

{ **pairs }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, location:, comments: []) ⇒ AssocSplat

Returns a new instance of AssocSplat.



1996
1997
1998
1999
2000
# File 'lib/syntax_tree.rb', line 1996

def initialize(value:, location:, comments: [])
  @value = value
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



1994
1995
1996
# File 'lib/syntax_tree.rb', line 1994

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



1991
1992
1993
# File 'lib/syntax_tree.rb', line 1991

def location
  @location
end

#valueObject (readonly)

untyped

the expression that is being splatted



1988
1989
1990
# File 'lib/syntax_tree.rb', line 1988

def value
  @value
end

Instance Method Details

#child_nodesObject



2002
2003
2004
# File 'lib/syntax_tree.rb', line 2002

def child_nodes
  [value]
end

#format(q) ⇒ Object



2006
2007
2008
2009
# File 'lib/syntax_tree.rb', line 2006

def format(q)
  q.text("**")
  q.format(value)
end

#pretty_print(q) ⇒ Object



2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
# File 'lib/syntax_tree.rb', line 2011

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("assoc_splat")

    q.breakable
    q.pp(value)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



2022
2023
2024
2025
2026
2027
2028
2029
# File 'lib/syntax_tree.rb', line 2022

def to_json(*opts)
  {
    type: :assoc_splat,
    value: value,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end