General Ruby Flashcards
General Ruby
check whether a value would be included in a given range
cover?(obj) => true or false
ex
(0. .100).cover? 50 #=> true
(0. .100).cover? 50.5 #=> true
General Ruby
quotes used with string interpolation
”
double quote
General Ruby
ternary syntax
expression ? true_value : false_value
General Ruby
nameless methods that are passed to methods as a parameter
blocks
General Ruby
object that is a block of code that can be bound to a set of local variables
proc
General Ruby
anonymous functions that can be saved to variables
lambdas
General Ruby
lambda syntax
prnt = lambda { |string| puts string }
prnt = -> (string) { puts string }
prnt.call (“my string”)
> my string => nil
General Ruby
lambdas compared to procs
stricter argument passing and localized returns
General Ruby
operator to signify when you are passing Procs/Lambdas/Methods as a block
&
General Ruby
case
syntax
case
when expression1
value1
when expression2
value2
else
default
end
General Ruby
easy way to create an array of strings (with interpolation)
%W(one two three four) => [“one”, “two”, “three”, “four”]
General Ruby
easy way to create a string without needing to escape quotation marks or line breaks (with interpolation)
%Q(John said, “My name is John”) => “John said, "My name is John"”
General Ruby
easy way to create an array of symbols (with interpolation)
%I(array of symbols #{1+1}) => [:array, :of, :symbols, :”2”]
General Ruby
difference between double quote and single quote strings
double quotes allow for interpolation and escape sequences (\n, \t, etc.), single quote does not allow for interpolation or escape sequences other than single quotes
General Ruby
proc syntax
Proc.new { |…| block } => a proc