Вы находитесь на странице: 1из 2

print "Your name?

"
GLOSSARY

if
elsif
else
while
until

for "variable" in 1..15


puts variable
end
Hash.new <------ create a hash ex: pets = Hash.new
then ex: pets = ["Mollie"] => cats

print <---- shows in command prompt, lined up ex: 1 2 3


puts <------ print and jumps a line
1
2
3

.length
.reverse
.uppercase
.lowercase
.capitalize <---- adds capital letter and converts the rest to lowercase
.each <---------- selects each string in an array ex: if my_array = [1, 2, 3] then
my_array.each selects [1, 2, 3] each turns individually.
.times <-------- multiplys by any given number ex: 30.times { print my_var }
.split <-------- my_var.split //// splits each word of a string into separate
blocks.

gets <------ prompts user to write. syntax: user_name = gets.chomp

chomp <----- used to cance line jump


break (if) <---- breaks loop
.include? <--------------- if "class" includes specific string

.gsub <----------- global substitution, used to replace a specific string. Syntax:


user_name.gsub!(/s/, "th") /////// /s/ <-- letter to be changed, "th" <-- to
replace with

! <--------- overwrites class instead of creating a copy. syntax: user_string!

Arrays: my_array = [1, 2, 3] <-------- brackets

-----------------------------------------------------------------------------------
------

true && true <------------ both statement need to be true


true || false <--------------- one statement needs to be true
!true <------------- ! true becomes false or vice versa

-----------------------------------------------------------------------------------
--------
first_name = gets.chomp
first_name.capitalize!
print "your surname?"
last_name = gets.chomp
last_name.capitalize!

print "Where do you live?"


city = gets.chomp
city.capitalize!

print "What country do you live in? (abbreviation)"


state = gets.chomp
state.upcase!

puts "Hi #{first_name}, your surname is #{last_name} and you live in #{city}. You
come from #{state}."

---------------------------------------------------
Loop i to 5

i = 0

while
i < 5
puts i

i = i + 1
end
---------------

This prints i from 20 down to 0, jumping uneven numbers with the [next] function,
next if i % 2 != 0 <----------- remainder

i = 20
loop do
i -= 1
next if i % 2 != 0
puts "#{i}"
break if
i == 0
end

RAILSRAILSRAILSRAILSRAILSRAILSRAILSRAILSRAILSRAILSRAILSRAILSRAILSRAILSRAILSRAILSRAI
LSRAILSRAILSRAILSRAILSRAILSRAILSRAILSRAILSRAILSRAILSRAILSRAILSRAILSRAILSRAILSRAILSR
AILSRAILSRAILSRAILSRAILSRAILSRAILS

Insrer du ruby dans de l'HTML.


<% model = class.find %>

Вам также может понравиться