Class: Y2R::AST::Ruby::Statements

Inherits:
Node
  • Object
show all
Defined in:
lib/y2r/ast/ruby.rb

Constant Summary

Constants inherited from Node

Node::INDENT_STEP

Instance Method Summary collapse

Methods inherited from Node

#ensure_separated, #has_comment?, #hates_to_stand_alone?, #pass_trailer?, #single_line_width, #to_ruby

Instance Method Details

#ends_with_comment?Boolean

Returns:

  • (Boolean)


400
401
402
403
# File 'lib/y2r/ast/ruby.rb', line 400

def ends_with_comment?
  comment_after ||
    (statements.size > 0 && statements.last.ends_with_comment?)
end

#priorityObject



391
392
393
# File 'lib/y2r/ast/ruby.rb', line 391

def priority
  Priority::NONE
end

#single_line_width_base(context) ⇒ Object



378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/y2r/ast/ruby.rb', line 378

def single_line_width_base(context)
  case statements.size
    when 0
      0
    when 1
      statement_context = context.with_priority(priority)

      statements.first.single_line_width(statement_context)
    else
      Float::INFINITY   # always multiline
  end
end

#starts_with_comment?Boolean

Returns:

  • (Boolean)


395
396
397
398
# File 'lib/y2r/ast/ruby.rb', line 395

def starts_with_comment?
  comment_before ||
    (statements.size > 0 && statements.first.starts_with_comment?)
end

#to_ruby_base(context) ⇒ Object



367
368
369
370
371
372
373
374
375
376
# File 'lib/y2r/ast/ruby.rb', line 367

def to_ruby_base(context)
  combine do |parts|
    # The |compact| call is needed because some YCP AST nodes don't
    # translate into anything, meaning their |compile| method will
    # return |nil|. These |nil|s may end up in statement lists.
    statements.compact.each do |statement|
      parts << statement.to_ruby(context.with_priority(priority))
    end
  end
end