Most voted "ruby" questions
Ruby is a dynamic, interpreted, object-oriented, cross-platform, open-source language created by Yukihiro Matsumoto (Matz) in 1995. The [ruby] tag is for issues related to the Ruby language, including its syntax and its libraries. Specific questions about the Ruby on Rails structure should be marked with [ruby-on-Rails] and not [ruby].
Learn more…679 questions
Sort by count of
-
4
votes3
answers494
viewsInstalling ruby with rbenv
I have a question, I installed the ruby in Ubuntu, but it was installed without the rbenv, has any problem installing it now, or it will be necessary to remove it first?…
-
4
votes1
answer98
viewsputs e p in Ruby
What’s the difference between p and puts in Ruby? When I should choose to wear one or the other?
-
4
votes2
answers82
viewsHow to return null if no result is found with find_by?
I’m getting a return as an array ([]) of a scope with find_by and I wish the return to be empty (null). See below some snippets of the code: class Dispute::Conference < ApplicationRecord ...…
-
4
votes1
answer299
viewsHow do I use the break command within two loops in Ruby?
When the "break" command is executed in "if" there is a way to exit the internal and external loop ? not just one ? while (i < maior) do if tam1>tam2 for i2 in 0 .. tam2 do…
-
4
votes1
answer73
viewsAre methods objects in Ruby?
Ruby’s got the class Proc, that is defined in the documentation as Blocks of code that have been bound to a set of local variables. Once bound, the code may be called in Different contexts and still…
-
4
votes1
answer224
viewsHow to add values to an array of a Ruby array?
puts "Alunos\n\n" alunos = [["Daniel: ", "Nota: 10\n\n"],["Abima: ", "Nota: 10\n\n"], ["Wilame: ", "Nota: 10\n\n"],["Felipe: ","Nota: 10\n\n"]] puts alunos I wonder if it is possible to add a new…
-
4
votes1
answer105
viewsWhy does Ruby have two send and __send__methods?
Ruby objects have a method called send that we can call methods dynamically. class MyClass private def true_method? true end end Example: mc = MyClass.new mc.send(:true_method?)…
rubyasked 5 years, 11 months ago Danilo Cândido 713 -
4
votes1
answer58
viewsWhat is the difference between the function call with ":" and "."?
In ruby it is possible to make a call from some method, either from some object, either using :: how much using .. What is the difference between them?
-
4
votes3
answers982
viewsConcatenation in Ruby and . object_id
Hello, my friends! I was studying Ruby and reading the concatenation methods I noticed a slight difference. When I tested the first method using "+", I noticed that when using the .object_id it…
-
4
votes1
answer77
viewsHow do the methods used within classes work?
It is very common in Ruby to use methods within classes, such as attr_accessor, or even libraries, such as validates_presence_of, ruby on Rails. I would like to create: class Person add_name_getter…
rubyasked 4 years, 10 months ago Luiz Felipe 32,886 -
4
votes1
answer58
viewsWhat are Fibers in Ruby and how to use them?
I was trying to do a reverse proxy using Webrick when I discovered that the version I had installed from Webrick did not contain the methods necessary to make a "chunked" worthy reading. So I…
-
3
votes1
answer1745
viewsSyntax error, Unexpected keyword_end, expecting end-of-input
I’m in a lot of trouble (It may be ridiculous thing but I don’t know what to do anymore). The following error is appearing: Syntaxerror in Group::Groupsuserscontroller#create…
-
3
votes1
answer109
viewsLimit Aggregation by grouped item in Mongo
I have a collection composed as follows, only with much more data. { _id: ObjectId("db759d014f70743495ef1000"), tracked_item_origin: "winword", tracked_item_type: "Software", machine_user:…
-
3
votes1
answer69
viewsMap Substring Solr
I have the following question, I have the model city(name, uf, province) I’m trying to implement the Sunspot search method, but I’m getting it on my own: # modelCity.rb searchable do text :name end…
-
3
votes1
answer341
viewsWhat is the best way to add ENUM fields to the Rails 4 model?
I need to reference the field numbers status of the database, which are in the format ENUM, with the names of my model. What’s the best way to do that? models/item.Rb class Item <…
-
3
votes2
answers1157
viewsRails 4: Changing the "Development" database from Postgresql to Sqlite3 makes the Rails server error
Hello. For some reasons, I had to change my DB "Development" from Postgresql Rails back to Sqlite3. Only the page has stopped working and the error that appears in the server Rails output is this:…
-
3
votes1
answer66
viewsstrong_parameters in Rails using datetime
I’m using strong_parameters to create an object nested in a form. All my attributes work correctly, except those defined in datetime. There’s something special about getting datetime nestled?…
-
3
votes3
answers144
viewsShould I use Symbols in hashes and parameters to optimize memory usage in Ruby?
On this other question here I asked about :symbols and 'strings' and found that the use of :symbols optimizes memory usage by the application. My question is whether the same goes for hashing: hash…
-
3
votes1
answer491
viewsWhat is the difference between Controller and Helper methods?
Architectural and conceptual doubt: I own a model Item who possessed attributes nome_ptbr and nome_en. I did the following method: def display_nome nome_ptbr || nome_en end Where should I put these…
-
3
votes3
answers216
viewsIs it wiser to use client-side validations in Rails?
According to your own experience it is best to use validations on client-side? Because if we analyze, Rails, in the standard validations, sends the request, does the validation and then returns the…
-
3
votes5
answers2123
viewsHow to validate CIS in ruby?
To validate CPF and CNPJ I use 'brcpfcnpj' in Gemfile. But I couldn’t find anything to validate the CIS. Validating INSS Specific Registration in Ruby on Rails ?
-
3
votes1
answer884
viewsError: incompatible Character encodings: UTF-8 and ASCII-8BIT
Incompatible Character encodings: UTF-8 and ASCII-8BIT. {"utf8"=>"✓", "authenticity_token"=>"3cl0R8ghLDvPMGkh0I+LCrzQjmyu1donLE9y58rIT1k=", "post"=>{"title"=>"Somos apaixonados por…
-
3
votes1
answer173
viewsStatistics in Ruby on Rails
I have the following problem, I need my system to generate some statistical data from an array, for example: vetor = [1, 5, 2, 1, 6, 30, 2, 7, 2, 80] I need to extract some data from it, like:…
-
3
votes1
answer199
viewsHow to randomly shuffle an Array in Ruby?
I would like to have the items in an array shuffled. Something like this: [1,2,3,4].scramble => [2,1,3,4] [1,2,3,4].scramble => [3,1,2,4] [1,2,3,4].scramble => [4,2,3,1] and so on,…
-
3
votes1
answer79
viewsConverting Case to Underscore in Ruby
There is a ready-to-use function that converts Strings to Camel case for strings separated by underscores? I wish something like that: "CamelCaseString".to_underscore return "camel_case_string".…
-
3
votes1
answer80
viewsUTF-8: reading and inserting into Mysql via Ruby 1.8
I am using a script written in Ruby that parses some XML files and inserts the information in a Mysql group. It works perfectly well, but it’s giving me a headache now that my XML files have…
-
3
votes1
answer233
viewsUML Questions for Rails System
My question is this. Rails controllers, for basic CRUD operations, require various methods that are repeated throughout the application’s controllers. I’m drawing the diagrams for a TCC application…
-
3
votes1
answer839
viewsHow to download videos from youtube and convert them to mp3 using ruby?
I need a simple way in ruby, which allows to download youtube videos only I need the audio of the video (mp3).
-
3
votes2
answers500
viewsOrganize jQuery Ruby On Rails
I have an app in Rails 4 and after scaffolding it generates a *.js.coffee for each model, as I am not using coffeescript renamed to *.js and am trying to use jQuery. The problem is that I need to…
-
3
votes1
answer1596
viewsCheck if a value is present in a Ruby array
How do I check if a certain value is contained in a Ruby array? For example, I want to know if 'A' is present in the vector ['A','B','C'].
-
3
votes1
answer155
viewsMigration to Heroku
I’m migrating my DB app pro Heroku, the deploy worked: $ git push heroku master When trying to migrate the database according to the command $ heroku run rake db:migrate does not work and returns…
-
3
votes1
answer120
viewsAdd Time by converting to Ruby for seconds
I am trying to find the average difference between the creation date and the last update of the records of a table as follows: tickets = Ticket.all.where('updated_at IS NOT NULL') t =…
-
3
votes2
answers86
viewsFetch the various fields from the query
I have this darling: @tudo = Isolated.joins("LEFT JOIN resists ON resists.isolated_id = isolateds.id").joins("LEFT JOIN genes ON genes.isolated_id = isolateds.id LEFT JOIN stats ON stats.gene_id =…
-
3
votes1
answer1086
viewsManipulate . txt file and put it into a Ruby array
I need, from a file . txt that has multiple tweets (one on each line), to read this file and put in a variable in the following format: [1, "texto da primeira linha do arquivo"], [1, "texto da…
rubyasked 9 years, 5 months ago Pedro Luiz Tortella 57 -
3
votes1
answer45
viewsRuby doubt Apis
I was reading in the ruby documentation on link about the default ruby classes, but I saw that it has more classes than the documentation shows how to yaml, where can I find those Apis? I want to…
-
3
votes2
answers1232
viewsEnable CORS in api Rails
They’re using this one GEM to enable the CORS of my application. The code I have in my config/application.rb is as follows: config.middleware.insert_before 0, 'Rack::Cors' do allow do origins…
-
3
votes0
answers93
viewshow to collect retweets and replys from a ruby user
I’m doing a job and in it I need to collect the number of retweets and replys of 10 tweets from a Twitter user. In the code it is already possible to collect the number of followers and following…
-
3
votes1
answer363
viewsHow to Convert Binary Files to String Securely?
Operating System: Windows 10; Version of Ruby: 2.2.1; Server Application: Apache 2 (mod_cgi); I must create a script that reads a file, convert it to text and after a possible processing, send the…
-
3
votes1
answer254
viewsReplace string by holding the box (uppercase/lowercase)
How best to replace a pattern with a string keeping the box? For example, DAdo -> LAdo or dado -> lado.
-
3
votes1
answer1984
viewsWhat Ruby applications do you have besides the web?
I want to delve into Ruby, for the ease of the language, as well as Python, which for example, in my University use a lot for mathematical and scientific applications. I see a lot of Ruby usage with…
-
3
votes4
answers396
viewsSelect without id field (Ror)
I am with a very silly doubt, I am making a system with Ruby on Rails and I need to make a select where the id field does not come, the problem is that this field is always present, for example:…
-
3
votes1
answer88
viewsInfluence of ":" in Ruby
The Framework data validation parameters Ruby on Rails, use values with : before and after the word. validates :terms_of_service, acceptance: { accept: true, message: 'Mensagem de Validação' }…
-
3
votes1
answer126
viewsMultiple submits calling multiple methods in a single form
Hello! I have a form that contains two buttons, each button, when clicking, leads me to a different method within the same controller. How do I do what I need to do? Because I’m not getting it. form…
-
3
votes1
answer116
viewsHow do I collect a String and use it in an if?
puts "Tem dinheiro? s/n" x = gets.chomp if x = s puts "Vou viajar" else puts "Não vai ser dessa vez" end
-
3
votes2
answers155
viewsRails performing XHR request when loading pages
I have noticed that in every page/route exchange, the Rails *make a new request Ajax to search for this new data (HTML), and thus perform the page exchange. I did several searches but the closest I…
-
3
votes1
answer553
viewsDoubt regarding the ||= ruby operator
Hello I’m still starting in Ruby, and I have a question regarding the following code Main.Rb web_design = Livro.new "Ruby", "X", "9428", 56.40, :web_design android_dev = Livro.new "Java", "Y",…
-
3
votes1
answer300
viewsSumming values of a column of a Ruby-related entity
I am trying to build an application in Rails. I have a resource where the user registers products and sales. The relationship is too much for many, to pass an array of products for sales made of the…
-
3
votes1
answer157
viewsCreate an object with strong Ruby on Rails parameters
I need to create an object from only one button. I pass nothing to the method, I call only through the button. All the data I need I have access to the controller action I’m using. But I can not…
-
3
votes3
answers262
viewsMany to Many JSON POST - Rails 5 - Only API
Hello, I am developing an engine in Rails 5 where it will be just a blog API. It will be a simple system. Post has several Passions and Passions has several Posts. I made the relationship N…
-
3
votes1
answer278
viewsHow to call a script with arguments?
I’m a little overweight, and researching on Physical Fitness, I figured out how to calculate my caloric expenditure, through the heartbeat. So I created the following script: bpm = 150 massa = 70…