11
votes
3answers
391 views

Pretty way of keeping sensitive info out of a logged command string in Ruby?

I have a long command that I am building with shovels (<<), with the intention of eventually running system(command). I'd ...
8
votes
2answers
132 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 ...
7
votes
2answers
129 views

Generate permutations with symbols

Goal: Create a combination of emails based from inputted first name, last name, middle name, and a domain. Add in common separators. Then I'll check which one is correct with the rapportive API. This ...
4
votes
3answers
2k views

Split post string into hash

...
4
votes
2answers
81 views

Processing array of objects into two strings

I have an array of Item objects that each have a string particular and a numeric amount. I ...
4
votes
1answer
138 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 ...
4
votes
3answers
151 views

Number to words problem

This is a very long solution I've been working on to a Number to Words problem. I've identified that there's a lot of repeating logic (e.g. 'if writing > 0', 'writing = integer /',). How would you ...
3
votes
2answers
84 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 ...
2
votes
2answers
73 views

Transfer the format of an old string to a new string

First, I've extended the String class to detect uppercase and lowercase characters: ...
2
votes
2answers
146 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 ...
1
vote
1answer
106 views

Ruby html href parser working slow

I wrote this simple HTML parser in Ruby. Basically I have a folder that has files. Every file has crawled web pages. The only addition within these files is before the HTML content there is a page ...
1
vote
1answer
900 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 ...
1
vote
1answer
93 views

Ruby string splicer

So I came across an interesting problem awhile back, and I finally got around to solving it. Basically, it needs to allow the user to provide two words, and have them progressively splice together, ...
0
votes
1answer
106 views

Is this the most efficient way to track word changes in a string?

I'm working on a writing platform and am using a modified version of the Levenshtein distance algorithm to track a writer's engagement with their writing. It tracks not only words added to their ...
-2
votes
2answers
75 views

Remove leading, trailing and repeated dashes from a string [closed]

How do I refactor this? '-hello--world-'.chomp('-').squeeze('-').reverse.chomp('-').reverse # => 'hello-world'