What we learned
Do not repeat yourself;
Do not create objects that you do not need;
•
•
Slide 131
Slide 131 text
What we learned
Do not repeat yourself;
Do not create objects that you do not need;
Use bang methods to modify an object instead of
creating a new one;
•
•
•
Slide 132
Slide 132 text
What we learned
Do not repeat yourself;
Do not create objects that you do not need;
Use bang methods to modify an object instead of
creating a new one;
Use methods like insert to modify a string instead of
creating a new one;
•
•
•
•
Slide 133
Slide 133 text
What we learned
Do not repeat yourself;
Do not create objects that you do not need;
Use bang methods to modify an object instead of
creating a new one;
Use methods like insert to modify a string instead of
creating a new one;
Think of an algorithm that does not use much memory.
•
•
•
•
•
97532.57 → 97,532.57
def add_delimiters(string, number, options)
offset = number > 0 ? 0 : 1
index = -5 - options[:precision]
while offset - index <= string.size do
string.insert(index, ",")
index -= 4
end
end