Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
0 votes
0 answers
36 views

ruby function adding pkg exclusion if not already exists in each repo defined in repo file

I am trying to create ruby function (within chef cookbook) adding package exclusion string to each repo defined in /etc/yum.repos.d/repo.repo. In example, for pkg zabbix* it search each repo and add '...
ariva's user avatar
  • 11
1 vote
1 answer
114 views

Ruby Error - Expected Array or String, Got Hash

EDIT - I've re-added the commented out sections to include the other methods I've attempted to solve this to hopefully provide more insight into my process. As of now this program is working, but it ...
Zach S's user avatar
  • 15
2 votes
4 answers
172 views

Ruby: Check if string contains substring and nothing else

Users can upload a CSV file to my service. The CSV needs to have two column names and nothing else. One column needs to be "email" and the other "credit" and nothing else can be in ...
ToddT's user avatar
  • 3,210
1 vote
2 answers
206 views

Ruby - Converting Small Float Numbers to String

I've noticed that small number floats, like 0.00000000345 end up getting converted to scientific notation, ie, 3.45e-9. This makes sense, but it looks like if I convert the float to a string (as I'd ...
irrelevant_data's user avatar
1 vote
1 answer
89 views

Ruby replace backslash with double backslash in a String [duplicate]

I have this little problem that bugs me. I need to double every backslash in a string, for exaple, If have a string 1 \ 2, I whish to transform it into 1 \\ 2. I don't see why the code below fails. ...
Nicola Mingotti's user avatar
1 vote
3 answers
99 views

String comparison in Ruby not returning correct test

I am trying to test for a palindrome but this code never returns true in the test. for a in (0..(myString.length/2)) do if (myString[a] == myString[myString.length-a+1]) p = true else p = ...
dromologue's user avatar
0 votes
2 answers
88 views

how to find an integer in a string in which only the preceeding character is known, and there is a max of 2 digits, in Ruby

I have a string such as x = '4x4 @ 32" hjy w/ R43 potter' x = '4x4 @ 32" hjy w/ R4 26 potter' x = 'Restful4 4 @ 32" hjy R8 26 potter' I need to get the digits with a preceding R, i.e....
jay's user avatar
  • 1
1 vote
4 answers
81 views

Extracting substring from the middle of a string in Rails

I'm trying to extract a substring from a class type returned as a string: '::Pos::EmailNotice' 'Pos::EmailNotice' '::Pos::CallNotice' 'Pos::CallNotice' So if I get a string 'Pos::{type}Notice', I ...
Donslaught's user avatar
0 votes
1 answer
41 views

Convert string to nested Ruby Hash [] get method

I have a string like '[field1][field2]' that I need to use to access a nested field from a Hash object. Basically, I want to do hash_obj['field1']['field2']. How can I transform that string to ...
Pedro's user avatar
  • 1
1 vote
3 answers
119 views

ruby : compare two words and extract uncommon letters out of it

I have to create a program which takes user inputs for two words, and extract unique letters from both. eg: two words are "extrapolation" and "among" after removing the common ...
Seby's user avatar
  • 127
4 votes
1 answer
127 views

How can I escape a Ruby string containing newlines (and possibly other special characters) to a valid shell variable value?

I need to write a Ruby function which generates a correct Bash export statement given a variable name and the value it should be assigned to. My current attempt is def export(variable, string) "...
Alexey Romanov's user avatar
0 votes
2 answers
79 views

Ruby string replace without capture group

Ruby's String.sub(pat, txt) family of functions performs substitution and supports capturing groups in txt even if pat is a plain string (at least it seems to support \0 to print all of pat in the ...
elbrunovsky's user avatar
0 votes
1 answer
442 views

How can I validate that a field is either empty or a number?

I want to validate if a received param is either an empty string or a positive number. I tried with: validates :my_field, presence: true, if: ->{ ((my_field.is_a? String) && ...
Andres Carretero's user avatar
1 vote
1 answer
104 views

Does Ruby guarantee that eval(str.inspect) == str?

I recently found myself needing to generate a simple Ruby script based on user input, some of which needs to be included in the script as a string literal. While in my specific case this input comes ...
Ilmari Karonen's user avatar
2 votes
2 answers
122 views

Why does #match return the correct result, but #scan finds only only one letter?

Background for Question I'm using Ruby 3.2.1, and I know that changes have been made to Ruby's regexp engine. That may or may not be relevant here. However, I get unexpectedly different behavior from ...
Todd A. Jacobs's user avatar

15 30 50 per page
1
2 3 4 5
198