Ruby Flashcards
how to comment in ruby?
#
how to print in ruby?
puts and has a new line returns nil
p returns the argument
print no new line
what does puts return?
nil as in ruby everything returns something
how to define a variable?
gretting = ‘hello world’
how to define a function?
def greeting(say_something)
puts ‘hello’
end
can u call a function before u define it?
no u must define it first
what is the difference between single quotes and double quotes?
with single quotes u can’t do string interpolation
how to concatenate strings?
with +
how to do string interpolation?
with “ #{variable} “
how to know the type of the variable?
variable.class
what is an important rule in ruby?
everything is an object
how to know the built in methods for a variable?
variable.methods
how to convert a variable to a string?
variable.to_s
can u chain methods in ruby?
yes
how to know the length of a variable?
variable.length
how to reverse a string?
variable.reverse
how to capitalize a variable?
variable.capitalize
how to check if a variable is empty?
variable.empty?
how to check if a variable in nil?
variable.nil?
how to replace a part of a string?
variable.sub
what is the difference between sub and gsub?
gsub replaces multiple occurances