Class: Y2R::AST::Ruby::Block

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

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

Instance Method Details

#priorityObject



1317
1318
1319
# File 'lib/y2r/ast/ruby.rb', line 1317

def priority
  Priority::ATOMIC
end

#single_line_width_base(context) ⇒ Object



1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
# File 'lib/y2r/ast/ruby.rb', line 1299

def single_line_width_base(context)
  if !args_have_comments?
    args_context = context.with_priority(Priority::NONE)
    args_width   = list_single_line_width(args, 2, args_context)

    statements_context = context.with_priority(Priority::NONE)
    statements_width   = statements.single_line_width(statements_context)

    if !args.empty?
      3 + args_width + 2 + statements_width + 2
    else
      2 + statements_width + 2
    end
  else
    Float::INFINITY
  end
end

#to_ruby_base(context) ⇒ Object



1291
1292
1293
1294
1295
1296
1297
# File 'lib/y2r/ast/ruby.rb', line 1291

def to_ruby_base(context)
  if fits_current_line?(context) && !args_have_comments?
    to_ruby_base_single_line(context)
  else
    to_ruby_base_multi_line(context)
  end
end