Tagged Questions
0
votes
2answers
53 views
A pattern to destructively extract items from an array
I want to efficiently (few intermediate objects) and neatly (few lines and easy to read) filter an array, removing and returning rejected items. So like a call to delete_if except instead of returning ...
3
votes
3answers
107 views
Most efficient way to iterate through arrays/can I use .times method in place of while method?
I created a quick program to test the precision of randomness generated by the .rand method. The primary question is whether I can use the .times method in place of the while code blocks to increase ...
3
votes
2answers
208 views
How can I optimize this array.each in ruby?
I'm trying to optimize this bit of code and I thought I'd throw it out here to see if anyone has any ideas. I've been testing the performance using Benchmark.measure {...} and wrapping the entire ...
4
votes
3answers
1k views
split post string into hash (ruby)
if(env['REQUEST_METHOD'] == 'POST')
$post = {}
post = env['rack.input'].read.split('&')
post_split = Array.new
post.each{|x| post_split << x.split('=')}
post_split.each{|x|
...
2
votes
1answer
132 views
Ruby: working with arrays
I am working on a script that collects all comments from my DB and inserts them into a hash. I then do a collect on the comments hash and split the comments into two separate comment hashes ...