Skip to content

Instantly share code, notes, and snippets.

@idimitrov07
Created June 19, 2016 14:56
Show Gist options
  • Select an option

  • Save idimitrov07/d25e7b958a09c304af43012b8e86795d to your computer and use it in GitHub Desktop.

Select an option

Save idimitrov07/d25e7b958a09c304af43012b8e86795d to your computer and use it in GitHub Desktop.
alphabet = ["a", "b", "c"]
alphabet << "d" # Update me!
caption = "A giraffe surrounded by "
caption << "weezards!" # Me, too!
if 1 < 2
puts "One is less than two!"
end
# refactored
puts "One is less than two!" if 1 < 2
#######
if 1 < 2
puts "One is less than two!"
else
puts "One is not less than two."
end
# refactored
puts 1 < 2 ? "One is less than two!" : "One is not less than two."
##################
puts "What's your favorite language?"
language = gets.chomp
if language == "Ruby"
puts "Ruby is great for web apps!"
elsif language == "Python"
puts "Python is great for science."
elsif language == "JavaScript"
puts "JavaScript makes websites awesome."
elsif language == "HTML"
puts "HTML is what websites are made of!"
elsif language == "CSS"
puts "CSS makes websites pretty."
else
puts "I don't know that language!"
end
#refactored
puts "What's your favorite language?"
language = gets.chomp
case language
when "Ruby"
puts "Ruby is great for web apps!"
when "Python"
puts "Python is great for science."
when "JavaScript"
puts "JavaScript makes websites awesome."
when "HTML"
puts "HTML is what websites are made of!"
when "CSS"
puts "CSS makes websites pretty."
else
puts "I don't know that language!"
end
##################
for i in (1..3)
puts "I'm a refactoring master!"
end
# refactored
3.times { puts "I'm a refactoring master!" }
age = 26
# Add your code below!
age.respond_to?(:next)
puts "Hello there!"
greeting = gets.chomp
# Add your case statement below!
case greeting
when "English" then puts "Hello!"
when "French" then puts "Bonjour!"
when "German" then puts "Guten Tag!"
when "Finnish" then puts "Haloo!"
else puts "I don't know that language!"
end
favorite_book = nil
puts favorite_book
favorite_book ||= "Cat's Cradle"
puts favorite_book
favorite_book ||= "Why's (Poignant) Guide to Ruby"
puts favorite_book
favorite_book = "Why's (Poignant) Guide to Ruby"
puts favorite_book
def multiple_of_three(n)
n % 3 == 0 ? "True" : "False"
end
my_array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
my_array.each { |el| puts el if el % 2 == 0 }
95.upto(100) { |num| print num, " " }
# Prints 95 96 97 98 99 100
"L".upto("P") { |al| puts al }
def a
puts "A was evaluated!"
return true
end
def b
puts "B was also evaluated!"
return true
end
puts a || b
puts "------"
puts a && b
favorite_things = ["Ruby", "espresso", "candy"]
puts "A few of my favorite things:"
favorite_things.each do |thing|
puts "I love #{thing}!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment