December 2010
4 posts
1 tag
Delay your Javascript execution
There’s a Prototype helper method called delay, so you can more precisely say when something will happen.
For example, you can do stuff like this inside your RJS files:
page["old_element"].visual_effect :blind_up, :duration => 0.5
page.delay(0.5) do
page.replace :old_element, :partial => "new_element"
page["new_element"].visual_effect :blind_down
end
Check out the delay...
2 tags
Array#first and Array#last parameters
Did you know you can pass a number parameter to Array#first and Array#last?
x = [1,2,3,4,5,6,7,8,9,10]
x.first 5
=> [1,2,3,4,5]
x.last 2
=> [9,10]
This tip was submitted by Alfred Nagy.
1 tag
42
You know you can access the 42nd element of an Array like this:
my_array[41]
In Rails, you can also access this element with the forty_two method:
my_array.forty_two
Check out the Array#forty_two method.
1 tag
Big Numbers
Your number has too many zeros? In ruby you can make that more readable (and easier to write!) by using underscores:
moneys = 1_000_000.00
=> 1000000.0