Skip to content

Instantly share code, notes, and snippets.

@analogrelay
Last active March 29, 2021 18:29
Show Gist options
  • Save analogrelay/84337a94a9c8563885ea2b34db529663 to your computer and use it in GitHub Desktop.
Save analogrelay/84337a94a9c8563885ea2b34db529663 to your computer and use it in GitHub Desktop.
Ruby Pop Quiz
names = [ "aaron", "abbot", "betty", "brian" ]
def starts_with_a(name)
return name.start_with? "a"
end
puts "filtering"
def filter_by_method(a)
a.select { |n| starts_with_a n }
end
def filter_by_block(a)
a.select { |n| return n.start_with?("a") }
end
puts "filtered by method: #{filter_by_method(names)}"
puts "filtered by block: #{filter_by_block(names)}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment