Questions tagged [ruby]

Ruby is a multi-platform open-source, dynamic object-oriented interpreted language, created by Yukihiro Matsumoto (Matz) in 1995. The [ruby] tag is for questions related to the Ruby language, including its syntax and its libraries. Ruby on Rails questions should be tagged with [ruby-on-rails].

Filter by
Sorted by
Tagged with
-2
votes
1answer
43 views

Do math across two arrays

I need to subtract one array from another, by index: a = [3,4,3,5] b = [1,2,2,1] c = [2,2,1,4]
0
votes
0answers
18 views

Back to the designated point with anchor

How can i do stuff like that in ruby: f = 0 #ANCHOR GO BACK HERE while f = 0 ... some code f = 1 end #ANCHOR FROM HERE It's sth like goto in pascal i belive, but i'm not sure. Could somebody help ...
1
vote
1answer
45 views

Ruby include/extend Module: a class method - Beginner

I've been reading this article on the difference between include & extend in ruby. If I have this module, I understand how the first and second methods of the module will be used in the class. ...
0
votes
1answer
37 views

I keep on getting an error relating to my hash

I made a hash on Repl.it, and I've tried everything but I keep getting the same error. I've done more research on hashes and I've learnt a lot. I'm fourteen and I've already run into a mojor problem ...
-2
votes
1answer
34 views

when do you prefer asterisk param over options hash in ruby method signature

When is it more appropriate to write a ruby method signature like this def truncate(text, *values) over def truncate(text, options = {}) Both seem to been common at rails
0
votes
0answers
23 views

URI must be ascii only [duplicate]

I'm creating a scraping program using Ruby I will ask a question because a program that used to work without problems has stopped working. When reading Japanese The error that appears is the title ...
0
votes
1answer
34 views

Date conversion in UTC

I am working ruby on rails. In that I have a doubt in date conversion from current timezone to UTC. The date conversion function is function date_conversion(date){ out = moment(date, "DD/MM/YYYY"...
0
votes
4answers
67 views

Get the average of numbers in an array which is the values of an hash

in a Ruby program I have an hash which has normal strings as keys and the values are array of numbers: hash_1 = {"Luke"=> [2,3,4], "Mark"=>[3,5], "Jack"=>[2]} And what I'm looking for is to ...
1
vote
4answers
61 views

How to make a repeated string to the left be deleted without using While?

For example, I have this string of only numbers: 0009102 If I convert it to integer Ruby automatically gives me this value: 9102 That's correct. But my program gives me different types of numbers: ...
1
vote
0answers
24 views

I can not run my migrated diaspora pod at all “bundle (LoadError)”

When I run the diaspora server by script/server there are problems with web.pid sidekiq1 load_external_pid_file: pid_file not found crashed? in the log "eye_processes_stderr.log" it is ...
1
vote
2answers
56 views

Is there a a function in Ruby to increment an objects variable inside an array in this example?

The drop1.amount or drop2.amount of Drop object in this example will not increase after the first time theyre run through. class Drop attr_accessor :item, :price, :amount end drop1 = Drop.new() ...
0
votes
0answers
16 views

Convert seconds to human readable format [duplicate]

For a tool I'm writing in ruby, at one point I'm processing an Integer storing some number of seconds (which could be as small as say 30 seconds, ranging to as large as a few days). Ideally, I'd like ...
0
votes
1answer
36 views

return instance through nested iteration

For customer_favs I was able to save all the instances of a favorite for the current customer I am working with. The favorite for a customer consists of the customer id and restaurant id. With that I ...
0
votes
0answers
23 views

How do I return the Nth fibonacci number [duplicate]

I'm learning Ruby and in this homework, I need to create a method to find one or more numbers of the Fibonacci sequence. I need to return the F(0) element in a Fibonacci sequence, I found some codes ...
0
votes
1answer
29 views

array iteration for ruby on rails

Each favorite consists of the customer id and restaurant id. I am basically trying to iterate through all the favorites and I am trying to see if the current customer.id is equal to the customer_id of ...
0
votes
1answer
23 views

How to use adapter to prevent Faraday from changing capitalize headers

I'm using Faraday to create an SDK that will interact with an API, and I need to send two headers API_SIGNATURE and API_REQUEST_TIME, so that's what I've created: class APIClient def initialize(...
1
vote
1answer
31 views

Syntax for the minimum Ruby version

The following starts a Gemfile: source "https://rubygems.org" ruby "~> 2.4.5" This approach is based on the answer How Can I Specify A Minimum Ruby Version in a Gemfile? : Already possible ...
1
vote
1answer
42 views

How to use flash[] to store an email

I mostly understand what flash[] does, so I don't think that's the issue, but I think I have a syntax error somewhere? Documentation and Google are not helping, and I can't find a similar question on ...
0
votes
0answers
13 views

Installing wdm gem on JRuby 9.2.8.0 on Windows

We're converting a Rails project from 2.3 to 5. One of the many changes is startup message: Please add the following to your Gemfile to avoid polling for changes: gem 'wdm', '>= 0.1.0' if Gem....
0
votes
0answers
17 views

SystemStackError (stack level too deep) RVM 1.9.3

I have an error when running the rails server SystemStackError in UsuariosController#login stack level too deep activesupport (3.1.12) lib/active_support/callbacks.rb:396 I currently have this code ...
1
vote
1answer
17 views

Trouble installing pg

I've been trying to install an api that says to use bundle install rails s But when I do bundle, I get this error: An error occurred while installing pg (0.18.1), and Bundler cannot continue. ...
1
vote
0answers
46 views

gets function is causing an Invalid argument error

I'm having to learn ruby (not rails) due to a device that only runs ruby installed code. I'm currently using v 1.9.3 on my Windows 10 desktop to study the syntax and I can't run any examples with the ...
1
vote
2answers
43 views

How to create multiple links from a single array of strings Rails - Ruby

I know it might seem simple but I've tried to create multiple links from this array in Rails array = ["/uploads/content/attachment/folder/file1.pdf/file2.pdf/file3.pdf"] What I want to do is create ...
0
votes
1answer
24 views

Downloading all files from URL with extension filter

I want to download all files from FTP or HTTP using extension filter For example, I have one URL that contains many MKV files and I want to set the extension filtering to download all MKV files from ...
0
votes
1answer
21 views

Blocked host: localhost ruby on rails 6.0.0

I am developing my first rails 6 app but when I try to serve it in development environment behind my nginx server, I find this message I tried adding the configuration mentioned in the error in ...
0
votes
0answers
18 views

How to merge template and JSON with Mustache gem?

How to merge template and JSON with Mustache gem? I can't figure out whats the problem with my code. doc_controller def show # Merge template and JSON with Mustache @merged_template = ...
1
vote
3answers
56 views

How to dehumanize ago time from humanize strings in Ruby?

Is there a way to dehumanize a duration string as follows to get the actual utc timestamp? For example: "1.hour.ago 25.minute.ago 1.second.ago" convert back Fri, 18 Oct 2019 16:09:10 UTC +00:00 the ...
0
votes
1answer
24 views

Finding element and entering in Ruby Selenium

I'm new to the Selenium and Ruby and Cucumber/Gherkins world and am trying a simple script to navigate to the Google page, find the search bar and enter a word and press enter or find the "Google ...
1
vote
1answer
27 views

Virtual Host running a server on another port on Webrick

This is probably a dump question, but I'm trying to run two Webrick 'servers'. One on port 8080 and one on port 8443. I could start up two servers in 2 threads, but I saw this: https://github.com/ruby/...
1
vote
1answer
31 views

Faraday is changing my headers from uppercase to capitalize case

I'm using Faraday to create an SDK that will interact with an API, and I need to send two headers API_SIGNATURE and API_REQUEST_TIME, so that's what I've created: class APIClient def initialize(...
-1
votes
2answers
55 views

How can i replace a parameter by looping parameters in ruby?

I have an array of parameters and i want to replace all parameters by looping over array in ruby on rails. I am using before_action in controller as before_action :cost_format This is an array of ...
0
votes
1answer
28 views

Heroku and ruby on rails: Deploy works, but running app fails do to usual sqlite3 error

I know that this problem is common, and a lot of questions here on S.O. presents the same solution, to install pg instead of sqlite3 and move sqlite3 under development group. I already did this. I'...
2
votes
1answer
38 views

Why does using a joins and includes with find_each result in an incorrect iterating count

I have a relation like this users = User.joins(:occupation).includes(:occupation) count = 0 users.find_each do |u| count += 1 end count count doesn't return the same number as users.count It ...
-2
votes
0answers
22 views

How to do a HTTP Request to an external REST Service (my own domain) from AWS Lambda

I am creating a Lambda Function over ruby to enrich some data passed by IoT Things with IoT Rule but, each time I require some HTTP gem I get an Time Exceeded Exception. I have tried with 'net/http', '...
0
votes
2answers
59 views

Understanding Ruby sort_by

I am new to ruby and I struggle understanding sort_by!. This method does something magically I really don't understand. Here is a simple example: pc= ["Z6","Z5","Z4"] c = [ { id: "Z4", ...
0
votes
0answers
33 views

Get value from select tag on view send to controller in var ruby and rails

please can help me. I am trying to get the values ​​of the "value" fields from my select_tag in rails and send it to the controller to use in variables to execute some commands, could help me follow ...
-1
votes
2answers
35 views

Why are changes to arrays in methods persistent, while changes to integers are not

aa = 5 bb = [5] def change(x,y) x = x + 5 y[0] = y[0] + 5 puts "Done" end change(aa, bb) p aa #=> 5 p bb #=> [10] After calling the change method using the arguments aa and bb, the ...
2
votes
2answers
62 views

Regex Ruby How to group every word within parentheses

I'm trying to get all the words between the parentheses after a specific word and the end of the string. For example, I have this case: p " some other text in downcase LOREM (foo, bar)".scan(/ LOREM ...
0
votes
1answer
33 views

Testing in Rspec a random weather methods functionality depending on the random number generated

I am trying to have 2 tests to check the functionality of a method within the Weather class. The random_weather method should change @status depending on the result of random_number. However I cannot ...
0
votes
1answer
14 views

Re-use failure message in rspec custom matcher

I have a custom matcher that uses expects in it's match block (the code here is simplified) RSpec::Matchers.define :have_foo_content do |expected| match do |actual| expect(actual).to ...
0
votes
0answers
11 views

How to debug Dashing / Ruby in IntelliJ IDEA?

Is it possible to run Dashing (Ruby/Coffeescript dashboard framework) in debug mode from within IntelliJ IDEA? I'm thinking of the Ruby parts. Or perhaps connecting IDEA to a running process? I want ...
2
votes
0answers
62 views

Ruby PageObject Design for Similar Page Sections

I'm using the Cheezy Page Object gem (which also means I'm using Watir, which also means I'm using Selenium). I also have the watir gem explicitly loaded. Anyway I have a site I am modeling with the ...
0
votes
1answer
31 views

Ruby Range test case SyntaxError

I'm running Ruby's Range test case but got an error in the line: assert_equal([*"a".."z", "aa"], ("a"..).take(27)) The error message is: test/ruby/test_range.rb:38: syntax error, unexpected ')' ......
0
votes
0answers
24 views

Rails 6 Capistrano Deployment - Webpacker Problem

When I try to deploy my Rails 6 application via Capistrano 3, until a few days everything worked fine. Now, when my application got bigger (more assets etc.) I decided to precompile my assets ...
1
vote
4answers
60 views

How to get the next and previous element in an array, Ruby

I have this array and need to replace its elements by the multiplication of its previous and next. I do the following: array.each_with_index{|element, index| next_element = array[index+1] ...
-3
votes
1answer
17 views

Build an API RESTfull app with Ruby use no Framework [on hold]

How to build an API RESTfull app with Ruby but use no framework (Ruby on Rails, Sinatra, etc). I've create an API app with Ruby on Rails and React, and I'm trying to find any sources to learn build ...
0
votes
3answers
136 views

Coding Challenge

So, recently I was checking one of a coding challenge. The problem was quite intriguing so just want to know whether there is a better way to do it in terms of time and space complexity. Problem: ...
1
vote
4answers
64 views

Iterating over different hashes with one method in Ruby

I've been working on a lab that wants you to build a method key_for_min_value that accepts an argument of a hash. The method should iterate over the hash and return the key that points to the smallest ...
0
votes
1answer
15 views

How to access <dc:creator> from a RSS XML feed using Nokogiri

Using Nokogiri I am able to access XML elements as follows: feed = "https://www.coachesvoice.com/category/masterclass/feed/" # Using HTTParty to get the the feed and save it as rss rss = HTTParty....
0
votes
5answers
45 views

Nested json from ruby hash

Trying to build a json out of Ruby hash require 'json' temp_rides = {"rides": {}} rides = {:lyft => "car", :scoot => "scooter", :blade => "helicopter"} rides.each do |key, value| temp_rides[...