Skip to content

Instantly share code, notes, and snippets.

@iamajvillalobos
Last active February 20, 2016 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamajvillalobos/bda4068b2173247eb32c to your computer and use it in GitHub Desktop.
Save iamajvillalobos/bda4068b2173247eb32c to your computer and use it in GitHub Desktop.
age = [26, 27, 24]
friends = { mark: 26, christopher: 27, aj: 24 }
def reject(enumerable)
if enumerable.is_a? Array
results = []
enumerable.each do |item|
results << item unless yield(item)
end
puts results.inspect
end
if enumerable.is_a? Hash
results = {}
enumerable.each do |name, age|
results[name] = age unless yield(name, age)
end
results
end
end
puts "using reject with array param"
puts reject(age) { |item| item > 26 }
puts "using reject with hash param"
puts reject(friends) { |name, age| age > 26}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment