Created
September 27, 2013 00:05
-
-
Save ivanbrennan/6722358 to your computer and use it in GitHub Desktop.
Different ways to discover what's true
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
lol! excellent use of == "WAT?" :D