-
Notifications
You must be signed in to change notification settings - Fork 732
Using Brakeman::AliasProcessor
presidentbeef edited this page Jan 3, 2012
·
3 revisions
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
x = 8 * 5
y = 32 / 8
y -= 2
x += y
x
becomes
x = 40
y = 4
y = 2
x = 42
42
x = "Hello"
y = x + " "
z = y + "world!"
puts z
becomes
x = "Hello"
y = "Hello "
z = "Hello world!"
puts("Hello world!")
dessert = ["fruit", "pie", "ice cream"]
dessert << "cookie"
dessert[1] = "cake"
dessert[1]
index = 2
index = index + 1
dessert[index]
becomes
dessert = ["fruit", "pie", "ice cream"]
["fruit", "pie", "ice cream", "cookie"]
["fruit", "pie", "ice cream", "cookie"][1] = "cake"
"cake"
index = 2
index = 3
"cookie"
x = ""
x << "hello" << " " << "world"
puts x
becomes
x = ""
"hello world"
puts("hello world")
x = [1]
x << 2 << 3
x
becomes
x = [1]
[1, 2, 3]
[1, 2, 3]
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)
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"
condition = true
if condition
x = "Yes!"
else
x = "No!"
end
puts x
becomes
condition = true
condition ? (x = "Yes!") : (x = "No!")
puts("Yes!")
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!"))
x.y = 10
x.y ||= "not this!"
p x.y
becomes
x.y = 10
x.y ||= "not this!"
p(10)
some_hash[:x] = 1
p some_hash[:x]
becomes
some_hash[:x] = 1
p(1)