Class: Templatecop::RubyClipper

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

Overview

Remove unnecessary part (e.g. ‘if`, `unless`, `do`, …) from Ruby code.

Defined Under Namespace

Classes: PrecedingKeywordRemover, TrailingDoRemover

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ RubyClipper

Returns a new instance of RubyClipper.

Parameters:

  • code (String)


7
8
9
# File 'lib/templatecop/ruby_clipper.rb', line 7

def initialize(code)
  @code = code
end

Instance Method Details

#callHash

Returns:

  • (Hash)


12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/templatecop/ruby_clipper.rb', line 12

def call
  [
    PrecedingKeywordRemover,
    TrailingDoRemover
  ].each_with_object(
    code: @code,
    offset: 0
  ) do |klass, object|
    result = klass.new(object[:code]).call
    object[:code] = result[:code]
    object[:offset] += result[:offset]
  end
end