Skip to main content

All Questions

Tagged with
0 votes
2 answers
85 views

Why does && operator not work inside a hash block but and operator does?

Given the following hash hash = {a: 5, b: 10} I want to check if all values are Integers and < 10. hash.all?{|key,value| value.is_a? Integer && value < 10} ## TypeError: class or module ...
pinkfloyd90's user avatar
0 votes
2 answers
84 views

Why is x-- a valid ruby statement but it doesn't do anything?

I know ruby doesn't support integer increment x++ or decrement x-- as C does. But when I use it, it doesn't do anything and doesn't throw an error either. Why? Edit: Sorry the code I actually found ...
eikes's user avatar
  • 5,012
-1 votes
2 answers
98 views

Using operators, how to set a variable equal to one of two other variables depending on which one has a value, in Ruby? [closed]

When there are only two states for instance variable "a", either it has a value or not, and there is only one possible state for instance variable "b", it has a value. I can set &...
Marc Auciello's user avatar
1 vote
1 answer
193 views

what is [] operator in Ruby

I don't get it that [] is an operator in ruby. I was wondering that if [] is an operator then what are these parenthesis {} & (). Are these also operators? What I know is that these symbols are ...
Mr.Muhammad Ramzan's user avatar
0 votes
2 answers
72 views

What is << stand for in ruby with integer

What is use of << I understand in array it is used for push but here I am not clear what is purpose of this in following code. Where it is being used integer. def array_pack(a) a.reverse....
Kamal Panhwar's user avatar
1 vote
4 answers
99 views

Is the order of the equality operator important in Ruby?

I have used the bcrypt library in my Ruby program. I noticed that the order of the equality operator seems to be important. Depending on which variable is left or right of the '==' I get a different ...
schande's user avatar
  • 608
0 votes
2 answers
156 views

Can operator precedence be changed in Ruby?

In Ruby, the operator precedence is (implicitly) defined, and documented in a couple of places, for example at Ruby operator precedence table. Some languages allow setting or changing the operator ...
Jochem Schulenklopper's user avatar
0 votes
2 answers
60 views

What does shorthand operator like (+=) in ruby really does?

While I can understand that x += 1 is equivalent to x = x + 1, I'm interested what it does in the background. I've tried in irb with x += 1 without first assigning value to x and surely I get an error,...
darkash's user avatar
  • 161
2 votes
2 answers
1k views

Logic OR / AND term evaluation order in Ruby

In Ruby, for the binary logic operators AND and OR, what's the order of evaluation of the terms, i.e., in an instruction like if bool1 || bool2 which boolean value is checked first? Is it left to ...
F.Webber's user avatar
  • 204
-2 votes
1 answer
189 views

What is the meaning of operator ==~ in Ruby? [duplicate]

I am modifying an existing ruby code. It has the following lines of code. Can somebody tell me what is going on. if string ==~ /^ABC/ do-something elsif string == "some string" do-...
Kartik Podugu's user avatar
-1 votes
3 answers
89 views

how can i rename a operator method with words, respecting sintax in ruby?

I'm trying to add an alias to a class method that uses an operator in ruby. My problem is that i would like to keep the new alias with the sintax of the operator def &(estrategia) does something ...
facuhump's user avatar
9 votes
2 answers
3k views

Rails—what does &= do?

To help future searches, it could also be described as "and equals" or "ampersand equals". I found this line in the Rails source code: attribute_names &= self.class.column_names What is the ...
Mirror318's user avatar
  • 12.4k
1 vote
4 answers
886 views

MULTIPLYING an array ELEMENT in while loop ruby

I have an array of integers, and I am attempting to multiply every second element by 2 moving backwards in the array. However, it does not seem to accept the * operator on the array item, results in ...
TomK's user avatar
  • 127
2 votes
1 answer
192 views

Is there an alternate syntax in Ruby for backticks?

In Ruby you can do a + b, which is equivalent to a.+(b). You can also override the +() method with def +(other); end. Is there an alternate syntax for backticks? I know that this works: class Foo ...
jleeothon's user avatar
  • 3,056
0 votes
4 answers
64 views

Ruby: why this WHEN-statement doesn't work with two conditions?

I have a case in my Ruby code that basically tries to match string in a couple of ways and do different things to it accordingly, kind of like that: case inst when Rx_inst1 (some function) when ...
MrVocabulary's user avatar

15 30 50 per page
1
2 3 4 5
12