Questions tagged as 'ruby'

3
answers

Is it more sensible to use client-side validations in Rails?

According to your own experience is it better to use client-side validations? Because if we analyze, Rails, in the standard validations, sends the request, does the validation and then returns the errors. This process, although not time consumi...
asked by 20.05.2014 / 21:13
1
answer

What are the main differences between Ruby and Crystal? [closed]

I saw a few days ago, some information about the Crystal language, but I would like to understand a little better about the main differences with Ruby. Examples: Which is faster and lighter in processing? Can everything done in Ruby be...
asked by 24.08.2017 / 13:25
1
answer

What is the difference between downcase and downcase!

I'm starting with Ruby and I came across the following code: user_input = gets.chomp user_input.donwcase! My question is why to use the exclamation point after the downcase.     
asked by 16.04.2014 / 15:33
2
answers

Should I use symbols in hashes and parameters to optimize memory usage in Ruby?

In this other question here I asked about :symbols and 'strings' and found that using :symbols optimizes memory usage by the application. My question is whether the same is true for creating hashes: hash = {:indice =&...
asked by 25.04.2014 / 13:41
1
answer

Influence of ":" in Ruby

The data validation parameters of the Ruby on Rails Framework use values with : before and after the word. validates :terms_of_service, acceptance: { accept: true, message: 'Mensagem de Validação' } validates :city, presence: true H...
asked by 01.07.2016 / 00:28
1
answer

Why 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?) mc.__send__(:true_method?)    Why do you...
asked by 27.11.2018 / 18:42
1
answer

Converting camel case to underscore in Ruby

Is there a ready-made function that converts strings into camel cases for strings separated by underscores? I would like something like this: "CamelCaseString".to_underscore return "camel_case_string" .     
asked by 10.08.2014 / 04:34
1
answer

What is the real need of the "initialize" method in Ruby?

def initialize(nome = "Anônimo", salario = 0.0) @nome = nome @salario = salario end To make it clear, what I can not understand is the difference between whether or not to use this method in a class and for what purpose it is eventually us...
asked by 07.11.2018 / 12:21
2
answers

String Comparison

Problem: I have to get the object that displays the content in the English language (lang == en) But depending on the search the order of the languages comes completely different and I tried to create a loop obj.take['http://dbpedia....
asked by 01.02.2017 / 02:20
1
answer

How to randomly shuffle an Array in Ruby?

I'd 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, randomly. How to do?     
asked by 10.08.2014 / 04:28