Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does %i or %I do in Ruby?

What's the meaning of %i or %I in ruby?

I searched Google for

"%i or %I" ruby 

but I didn't find anything relevant to Ruby.

like image 759
american-ninja-warrior Avatar asked Oct 31 '17 16:10

american-ninja-warrior


People also ask

What does || in Ruby mean?

a ||= b is a conditional assignment operator. It means: if a is undefined or falsey, then evaluate b and set a to the result. Otherwise (if a is defined and evaluates to truthy), then b is not evaluated, and no assignment takes place.

What does .first mean in Ruby?

The first() is an inbuilt method in Ruby returns an array of first X elements. If X is not mentioned, it returns the first element only. Syntax: range1.first(X) Parameters: The function accepts X which is the number of elements from the beginning. Return Value: It returns an array of first X elements.

What is %q in Ruby?

Alternate double quotes The %Q operator (notice the case of Q in %Q ) allows you to create a string literal using double-quoting rules, but without using the double quote as a delimiter. It works much the same as the %q operator.

How do you write an OR statement in Ruby?

In Ruby, “or” keyword returns the logical disjunction of its two operands. The condition becomes true if both the operands are true. It returns “true” when any one condition/expression is “true” and returns “false” only when all of them are “false”.


1 Answers

%i[ ] # Non-interpolated Array of symbols, separated by whitespace %I[ ] # Interpolated Array of symbols, separated by whitespace 

The second link from my search results http://ruby.zigzo.com/2014/08/21/rubys-notation/

Examples in IRB:

%i[ test ] # => [:test] str = "other" %I[ test_#{str} ] # => [:test_other]  
like image 195
Stanislav Mekhonoshin Avatar answered Oct 09 '22 22:10

Stanislav Mekhonoshin