6
votes
2answers
120 views

String substitutions in ruby and coding style

I wrote a short ruby script to generate various screenshots, and event though I am not completely new to ruby I rarely use it. Full script (41 LOC): https://gist.github.com/1229115 The string ...
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| ...
4
votes
1answer
75 views

Ruby: refactor simple string method for aligning DSV text

GOAL: Accept DSV strings where the delimiter may consist of more than one character Accept DSV strings where there are no embedded delimiters Output text with no modification to the source string ...
3
votes
2answers
33 views

How to refactor this Ruby method?

The new_string code in this method does not seem idiomatic. The goal is to not mutate the string passed in, which I believe is a good practice. This method changes all URL's in the string into an ...
2
votes
2answers
127 views

Simplify series of string manipulations in Ruby

I have a series of string manipulation, I realize this with the following code. I want it to be more elegant and readable such as str.sub_heading().sub_codeblock()..., how could I rewrite my code? ...
1
vote
1answer
368 views

Words counter with a hash

My problem is the following: I wrote a method, which counts words and returns a hash. There is a Ruby idiom which was found by me in some of the forums discussions, which I don't understand. Here is ...