Sha256: 67c73d22530f7d044c2f3ac12b0fbb41162ff2a6869334c942a3d9a7fc7ad67a

Contents?: true

Size: 587 Bytes

Versions: 4

Compression:

Stored size: 587 Bytes

Contents

Synvert::Rewriter.new "ruby_new_lambda_syntax" do
  description <<-EOF
Use ruby new lambda syntax

    lambda { # do some thing } => -> { # do some thing }
  EOF

  if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("1.9.0")
    within_files '**/*.rb' do
      # lambda { |a, b, c| a + b + c } => ->(a, b, c) { a + b + c }
      within_node type: 'block', caller: {type: 'send', message: 'lambda'} do
        if node.arguments.empty?
          replace_with "-> { {{body}} }"
        else
          replace_with "->({{arguments}}) { {{body}} }"
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
synvert-0.0.17 lib/synvert/snippets/ruby/new_lambda_syntax.rb
synvert-0.0.16 lib/synvert/snippets/ruby/new_lambda_syntax.rb
synvert-0.0.15 lib/synvert/snippets/ruby/new_lambda_syntax.rb
synvert-0.0.14 lib/synvert/snippets/ruby/new_lambda_syntax.rb