Skip to content

Instantly share code, notes, and snippets.

@ivanbrennan
Created September 27, 2013 00:05
Show Gist options
  • Save ivanbrennan/6722358 to your computer and use it in GitHub Desktop.
Save ivanbrennan/6722358 to your computer and use it in GitHub Desktop.
Different ways to discover what's true
#1
def is_vowel_elsif?(letter)
if letter == "a"
true
elsif letter == "e"
true
elsif letter == "i"
true
elsif letter == "o"
true
elsif letter == "u"
true
else
false
end
end
#2
def is_vowel_case?(letter)
case letter
when "a" then true
when "e" then true
when "i" then true
when "o" then true
when "u" then true
else false
end
end
#3
def is_vowel_if?(letter)
(["a","e","i","o","u"].each{|vowel| return true if letter==vowel}) == "WAT?"
end
#4
def one_line_is_vowel?(letter)
letter=="a" || letter=="e" || letter=="i" || letter=="o" || letter=="u"
end
#5
def is_vowel_arr?(letter)
vowels = ["a","e","i","o","u"]
vowels.include?(letter)
end
#6
def first_vowel(str)
str.scan(/a|e|i|o|u/).first
end
#7
def first_vowel_idx(str)
vowel = first_vowel(str)
str.index(vowel) if vowel != nil
end
@theevo
Copy link

theevo commented Sep 27, 2013

lol! excellent use of == "WAT?" :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment