# Using Brakeman::AliasProcessor

See here for an example of how to use Brakeman::AliasProcessor.

Below are some simple examples of what Brakeman::AliasProcessor can do.

```x = 1 + 2 + 3
x += 4
x```

becomes

```x = 6
x = 10
10```

## Simple Math

```x = 8 * 5
y = 32 / 8
y -= 2
x += y
x```

becomes

```x = 40
y = 4
y = 2
x = 42
42```

## String Concatenation

```x = "Hello"
y = x + " "
z = y + "world!"

puts z```

becomes

```x = "Hello"
y = "Hello "
z = "Hello world!"
puts("Hello world!")```

## Arrays

```dessert = ["fruit", "pie", "ice cream"]
dessert[1] = "cake"
dessert[1]

index = 2
index = index + 1

dessert[index]```

becomes

```dessert = ["fruit", "pie", "ice cream"]
["fruit", "pie", "ice cream", "cookie"][1] = "cake"
"cake"
index = 2
index = 3

## String <<

```x = ""
x << "hello" << " " << "world"

puts x```

becomes

```x = ""
"hello world"
puts("hello world")```

## << Chain

```x = [1]
x << 2 << 3
x```

becomes

```x = [1]
[1, 2, 3]
[1, 2, 3]```

## Unknown <<

```x = y.something
x << "blah blah"
x << 3
x```

becomes

```x = y.something
(y.something << "blah blah")
((y.something << "blah blah") << 3)
((y.something << "blah blah") << 3)```

## Hashes

```x = {:goodbye => "goodbye cruel world" }
x[:hello] = "hello world"

x.merge! :goodbye => "You say goodbye, I say :hello"

x[:goodbye]```

becomes

```x = { :goodbye => "goodbye cruel world" }
{ :goodbye => "goodbye cruel world" }[:hello] = "hello world"
{ :goodbye => "You say goodbye, I say :hello", :hello => "hello world" }
"You say goodbye, I say :hello"```

## Obvious If

```condition = true

if condition
x = "Yes!"
else
x = "No!"
end

puts x```

becomes

```condition = true
condition ? (x = "Yes!") : (x = "No!")
puts("Yes!")```

## Regular If

```if something
x = "Something is awesome!"
elsif something_else
x = "Something else is awesome!"
else
x = "This is the default!"
end

puts x```

becomes

```if something then
x = "Something is awesome!"
else
if something_else then
x = "Something else is awesome!"
else
x = "This is the default!"
end
end
puts((("Something is awesome!" or "Something else is awesome!") or "This is the default!"))```

## Or Equal

```x.y = 10

x.y ||= "not this!"

p x.y```

becomes

```x.y = 10
x.y ||= "not this!"
p(10)```

## Unknown hash

```some_hash[:x] = 1

p some_hash[:x]```

becomes

```some_hash[:x] = 1
p(1)```
##### Clone this wiki locally
You can’t perform that action at this time.