All Questions
7 questions
0
votes
2
answers
2k
views
Ruby format string with variable inside quotes
If I do
template_string = "class=btn submit-button %<additional_classes>"
format(template_string, additional_classes: 'some-class')
it works. However, if I do
template_string = "class='btn ...
0
votes
3
answers
176
views
Ruby titleize / convert "los angeles, ca" to "Los Angeles, CA"
I'm working on a project that uses locations entered by users and I'm looking for advice on how to correctly titleize a location such as "los angeles, ca".
Using Rails titleize, I get "Los Angeles, ...
0
votes
1
answer
2k
views
How do I properly escape % in call to printf in Ruby?
How do I properly escape % in call to printf in Ruby?
When I try to use %% (as in C),
value = 47
printf "To have a 60%% test average, your final exam must be at least %0.2f.\n" % [value]
I get this ...
2
votes
2
answers
817
views
Avoid double quote confusion when generating CSV files?
I am pushing some strings to a CSV file:
csv_string = CSV.generate({col_sep: ";", row_sep: "\n"}) do |csv|
csv << ["101-41", "Sparri, \"Violet\" (rod) (1 bunt á 10 stk.)"]
end
When the CSV ...
-2
votes
1
answer
44
views
How can I produce one whole string from iteration on array of arrays in Ruby [closed]
I have array of arrays looking something like this :
arr = [[f,f,f,f,f], [f,f,t,f,f], [f,t,f,t,f]]
and am I outputing it formatted on the console like this:
arr.each {|a| puts a.join.gsub('t','<b&...
3
votes
2
answers
275
views
Java equivalent of ruby's "Some sentence that I need a dynamic #{value}."
Do I have to formulate all of my strings in java like "Some static words" + variable + " some more static words." or is there a way to do something like the way ruby allows you to evaluate a section ...
1
vote
4
answers
571
views
ClassName to class_name
I'm sure this is an easy one for you geeks:
Say I have a String "ThisIsMyString" and I want to format it like "this_is_my_string" using Ruby.
How do I do that?
Matt