Skip to content

Instantly share code, notes, and snippets.

@ahimmelstoss
Created October 11, 2013 17:07
Show Gist options
  • Save ahimmelstoss/6938411 to your computer and use it in GitHub Desktop.
Save ahimmelstoss/6938411 to your computer and use it in GitHub Desktop.
# Download this file:
# https://gist.github.com/aviflombaum/872638777f7511d2a30a/download
# Run it from your terminal with:
# ruby ruby.basics.rb
# (Just make sure you are in the right directory)
# ======================================
# Ignore All This Code
# ======================================
@tests = 0
def test(title, &b)
@tests += 1
begin
if b
result = b.call
if result.is_a?(Array)
puts "#{@tests}. fail: #{title}"
puts " expected #{result.first} to equal #{result.last}"
elsif result
puts "#{@tests}. pass: #{title}"
else
puts "#{@tests}. fail: #{title}"
end
else
puts "#{@tests}. pending: #{title}"
end
rescue => e
puts "fail: #{title}"
puts e
end
end
def assert(statement)
!!statement
end
def assert_equal(actual, expected)
if expected == actual
true
else
[expected, actual]
end
end
class Object
def __
puts "__ should be replaced with a value or expression to make the test pass."
false
end
end
# ======================================
# Start Here - Make these tests pass.
# ======================================
# Define a method named is_a_vowel? that takes one
# argument and returns true or false depending on
# whether the argument is a vowel.
# Method definition goes here:
def is_a_vowel?(letter)
case letter
when "a", "e", "i", "o", "u"
true
else
false
end
end
# you can use == to compare a string to another string
# and check for equality.
# 1.
test 'that "a" is a vowel' do
is_a_vowel?("a")
assert is_a_vowel?("a")
end
# 2.
test 'that "e" is a vowel' do
is_a_vowel?("e")
assert is_a_vowel?("e")
end
# 3.
test 'that "i" is a vowel' do
is_a_vowel?("i")
assert is_a_vowel?("i")
end
# 4.
test 'that "o" is a vowel' do
is_a_vowel?("o")
assert is_a_vowel?("o")
end
# 5.
test 'that "u" is a vowel' do
is_a_vowel?("u")
assert is_a_vowel?("u")
end
# 6.
test 'that "b" is not a vowel' do
is_a_vowel?("b")
assert !is_a_vowel?("b")
end
# 7.
test 'that "c" is not a vowel' do
is_a_vowel?("c")
assert !is_a_vowel?("c")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment