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.
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.
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.
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.
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”.
%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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With