Skip to main content

All Questions

Tagged with
0 votes
1 answer
86 views

Undefined method `name' for an instance of Array (NoMethodError)

I am trying to add an element into an instance of array by using push(<<) to insert variables new_name and new_origin into ingredients array but I am receiving this error: undefined method `name'...
Sulsoyy's user avatar
-2 votes
1 answer
91 views

syntax error, unexpected ')', expecting '=' (SyntaxError) [closed]

Letters1 = Array["A","B"] password1 = nil while password1 != "A" letter1 = Letters1[rand(0...2)] letter2 = Letters1[rand(0...2)] password1 = (letter1) File.write(&...
Coder90000000's user avatar
0 votes
1 answer
79 views

How can I incrementally increase a displayed array element using a rails button?

I have two arrays @necklines and @skirts, made up of all Neckline models, and Skirt models respectively. I am attempting to show one neckline and one skirt at a time, and having two buttons to either ...
Mason's user avatar
  • 3
0 votes
2 answers
67 views

Generate array based on two others

I have two arrays: [["106373", "106374", "106375", "106376"], ["106377", "106378", "220183", "220184"], ["220185&...
Flávio's user avatar
  • 11
0 votes
6 answers
114 views

Locate index of mismatch in an array

I have an array that should contain the same value throughout and if there are mismatches, I want to pull the index of those mismatches. Example: [1,1,1,1,3,1,1,1,2,1,1,1] Output: [4, 8] What's the ...
Jeremy Thomas's user avatar
0 votes
1 answer
67 views

Iterating over a Nested array in ruby

test_scores = [ [97, 76, 79, 93], [79, 84, 76, 79], [88, 67, 64, 76], [94, 55, 67, 81] ] puts test_scores.any? do |scores| scores.all? { |score| score > 80 } end When I run the above code on ...
Md Arafat Hossain's user avatar
0 votes
2 answers
50 views

Ruby on Rails seems to corrupt a constant in a method

my Constant seems be be modified but how can it be. the environment is rails 7.0.7.2 Ruby 3.1.2p20 via rbenv Consider module ArrayTestMethods PROFILE_PARAMS = [["id","id"],["...
Qd1y's user avatar
  • 21
-1 votes
3 answers
153 views

Ruby complex strings array to array of float

I'm trying to convert this (rather complex) string array of float strings into an array of float with no luck: [ 5.85142857 6.10684807 6.15328798 6.31582766 6.96598639 7.61614512 7....
Seto's user avatar
  • 1,452
2 votes
1 answer
88 views

Ruby #union on Array reacts very strangely

I like to use the Array#union or #| method to return an array of objects where duplicates are removed. I have a custom implementation of eql? on my class. There is a really strange behaviour if I do ...
Lars Schirrmeister's user avatar
1 vote
2 answers
246 views

Matching of randomly ordered array when test nested hash with RSpec

In my RSpec tests I often have the challenge to compare deep nested hashes like this { foo: ["test", { bar: [1,2,3] }] } The values [1,2,3] are read from a DB where the order is not ...
23tux's user avatar
  • 14.5k
0 votes
5 answers
139 views

How to check if a value exists in the first member of a two dimensional array

I'm trying to check if any of the first value of a two-dimensional array has the value i'm testing. The array is like this [[2,5],[3,1],[4,1]] I want to check only the first member of the array (here ...
Tikroz's user avatar
  • 203
0 votes
1 answer
117 views

How do you efficiently chain array methods in Ruby

So let's say I have this MWE code: # see below for full code - not important here class RealEstate; attr_accessor :name; attr_accessor :living_space; attr_accessor :devices; def initialize(name, ...
sb813322's user avatar
  • 129
1 vote
2 answers
68 views

Ruby way instead of for loop in specific case of array iteration

Coming from other languages where for loop is predominant way of iterating, I am curious is there a better more Ruby style way to achieve below: q=[5,1,7,9,0,3,6,8,0] for i in 0..q.size/3-1 do one ...
ZoRaN's user avatar
  • 13
1 vote
2 answers
69 views

How to insert an object in an array of object while looping in rails

controller.rb def index @expenses = Expense.all.order(:expense_type_id) end @expenses looks like as below [#<Expense:0x00007faeb044c6e8 id: 1, amount: 120 expense_type_id: 1>, #<...
user12763413's user avatar
  • 1,337
0 votes
1 answer
64 views

why when I call a function passing a reference to an array, the array is changing in ruby? [closed]

I was following a tutorial on creating a little game in Ruby when I fell into a bug I couldn't understand. When I looked closely, I realized that the error was happening in line 51 of the fogefoge.rb ...
MR-RenatoBlue's user avatar

15 30 50 per page
1
2 3 4 5
512