All Questions
429 questions
-1
votes
1
answer
94
views
I need help formatting this code as a Ruby method [closed]
So, I have passing code for what I am trying to achieve. Now I need to format it in a method format that takes two parameters. I have more experience with JavaScript functions at this point and am ...
2
votes
4
answers
133
views
ruby 3.1.2 how to reference an object property as a method parameter
This may be trivial. I want to reference an object property from within an object method parameter list, if that makes sense.
Trivial example:
'tags'.ljust([calculated_length, obj.length].max)
where, ...
1
vote
5
answers
150
views
Selecting strings of repeated digits from an integer
I need to write a program that, given an integer, finds strings of repeated digits and returns them as an array. For example, given 1234555567899944, the program needs to return [5555, 999, 44].
Here'...
2
votes
1
answer
574
views
How to display array values in Shopify Script Editor?
With the holidays coming up, my team is working on developing a script for our Shopify store that prevents our customers from using discount codes if they have one of the following in their cart : ...
1
vote
1
answer
99
views
Extracting Nested Hash-Array Values to Individual String Values
I'm trying to extract the values inside a nested hash with values inside an array within a hash value (basically a nested hash-array value) into individual string values. Hash value sample is below:
{&...
-1
votes
1
answer
256
views
How to replace words from an array in a string with asterisks?
I have a string, that contains a sentence. Then I have an array, that have some words. I need to check, if that sentence contains words given in the array, or more specifically, even if words from the ...
0
votes
2
answers
142
views
Array and string in ruby
Hi amazing stackers!
date = "10/02/2021"
d1 = date.split("/")
d2 = d1.to_s
puts d1
puts d1.class
puts d2
puts d2.class
in the above code, d2 shows the data type "string" ...
0
votes
1
answer
397
views
In the Json output data fields to remove the leading and trailing quotes of the string array
In the Json output data fields the leading and trailing quotes of the string of array type has to be removed. The json data is getting displayed in the workato. We tried with ruby methods like gsub, ...
0
votes
2
answers
184
views
How to do operations on strings in array of hashes in ruby?
I have this array of hashes:
array = [{:ID=>"AAA", :Quantity=>1}, {:ID=>"BBB@ST050", :Quantity=>2}]
If the :ID key doesn't have the "@" character then I add ...
0
votes
2
answers
213
views
Ruby using .chars on strings inside of an array
I want to convert a given sentence into an array of arrays, where each nested array consists of the letters of each word, so that
"I am a dog" becomes [["I"], ["a", "...
-1
votes
1
answer
106
views
Unable to reverse each word in array in Ruby ( Without built-in function reverse)
I am trying to reverse each word in an array and here is what I have tried. I am unable to figure out why this code of array (word.size-1..0) won't give me any results in the new arr[].
Any help will ...
2
votes
3
answers
863
views
How do I convert a string to an array with spaces preserved in Ruby?
How do I convert a String: 'Hello world!' to an array: ['Hello', ' ', 'world!'] with all spaces preserved?
I tried to convert the string using the split method with different parameters, but I ...
0
votes
2
answers
103
views
count the distance between to strings in an array Ruby
i have an array
line_one = ["flinders street", "richmond", "east richmond", "burnley", "hawthorn", "glenferrie"]
user_input1 = "...
1
vote
2
answers
224
views
How to convert an array of string integers to an array of integers? Ruby
I have an array:
all_ages = ["11", "9", "10", "8", "9"]
and I want to convert it to an array of integers to hopefully make it easier to add them all ...
0
votes
1
answer
71
views
Remove and change a character on string [closed]
I have an array of strings. What I want is to remove from a string the character "," and the character "]" change it to "|".
string = 3.1321309062246026, 42....