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.



1968
1969
1970
1971
1972
# File 'lib/syntax_tree.rb', line 1968

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



1966
1967
1968
# File 'lib/syntax_tree.rb', line 1966

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



1963
1964
1965
# File 'lib/syntax_tree.rb', line 1963

def location
  @location
end

#valueObject (readonly)

untyped

the expression that is being splatted



1960
1961
1962
# File 'lib/syntax_tree.rb', line 1960

def value
  @value
end

Instance Method Details

#child_nodesObject



1974
1975
1976
# File 'lib/syntax_tree.rb', line 1974

def child_nodes
  [value]
end

#format(q) ⇒ Object



1978
1979
1980
1981
# File 'lib/syntax_tree.rb', line 1978

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

#pretty_print(q) ⇒ Object



1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
# File 'lib/syntax_tree.rb', line 1983

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



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

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