Class: RLSL::Prism::SourceUnit

Inherits:
Struct
  • Object
show all
Defined in:
lib/rlsl/prism/source_unit.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



7
8
9
# File 'lib/rlsl/prism/source_unit.rb', line 7

def body
  @body
end

#paramsObject

Returns the value of attribute params

Returns:

  • (Object)

    the current value of params



7
8
9
# File 'lib/rlsl/prism/source_unit.rb', line 7

def params
  @params
end

Class Method Details

.from_block(block) ⇒ Object



13
14
15
16
17
18
# File 'lib/rlsl/prism/source_unit.rb', line 13

def from_block(block)
  new(
    params: extract_params(block),
    body: block.body&.slice.to_s.strip
  )
end

.from_source(source) ⇒ Object



9
10
11
# File 'lib/rlsl/prism/source_unit.rb', line 9

def from_source(source)
  SourceUnitParser.new(source).parse
end

Instance Method Details

#to_sourceObject



34
35
36
37
38
39
# File 'lib/rlsl/prism/source_unit.rb', line 34

def to_source
  segments = []
  segments << "|#{params.join(', ')}|" unless params.empty?
  segments << body unless body.empty?
  segments.join("\n")
end

#without_paramsObject



30
31
32
# File 'lib/rlsl/prism/source_unit.rb', line 30

def without_params
  self.class.new(params: [], body: body)
end