adapted from this blog
# YAML
name: Jon
# YAML
object:
adapted from this blog
# YAML
name: Jon
# YAML
object:
# This is a skeleton for testing models including examples of validations, callbacks, | |
# scopes, instance & class methods, associations, and more. | |
# Pick and choose what you want, as all models don't NEED to be tested at this depth. | |
# | |
# I'm always eager to hear new tips & suggestions as I'm still new to testing, | |
# so if you have any, please share! | |
# | |
# @kyletcarlson | |
# | |
# This skeleton also assumes you're using the following gems: |
class CustomException < StandardError | |
attr_reader :message, :error_id | |
def initialize(message, error_id) | |
@message = message | |
@error_id = error_id | |
end | |
end | |
begin |
# Example 1 | |
begin | |
x = 5 / 0 | |
rescue | |
puts "Ohh no !!!" | |
ensure | |
puts "This will always execute" | |
end | |
# Example 2 |
1.upto 5 do |i| | |
puts i | |
end | |
# 1 | |
# ... | |
# 5 | |
5.downto 1 do |i| | |
puts i | |
end |
x = 10 | |
until x < 0 | |
p x | |
x -= 1 | |
end | |
# Output > | |
# 10 | |
# ... | |
# 0 |
number = 1 | |
case number | |
when 1 then puts "One" | |
when 2 then puts "Two" | |
else puts "Zero" | |
end |
cond1 = cond3 = true | |
cond2 = cond4 = false | |
if cond1 and cond3 then puts "1" end | |
if cond1 and not cond3 then puts "2" end | |
if cond1 or cond2 then puts '3' end | |
if cond1 && cond3 then puts '1' end | |
if cond1 && !cond3 then puts '2' end | |
if cond1 || cond2 then puts '3' end |
response = :greeting | |
if response != :greeting | |
puts 'Hey' | |
# ignore | |
else | |
puts 'Ok' | |
end | |
# Similar to |
response = :greeting | |
if response == :greeting | |
puts "Hello !" | |
elsif response == :shout | |
puts "Don't yel" | |
else | |
puts "Huh ?" | |
end |