Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# Definition of banning something
# to_ban = 'To prohibit (an action) or forbid the use of (something)'
EVERYTHING = -> (existing_bans) { def existing_bans.include?(obj); true; end }
@bans = []
ban_something = -> (how_to_ban) { how_to_ban.call(@bans) }
# Some simple tests
puts "** Some simple tests"
puts "-- Is Breathing banned? #{@bans.include?('Breathing')}"
puts "-- Is Walking banned? #{@bans.include?('Walking')}"
# Ban
puts "** Let's ban Religion"
ban_religion_lambda = -> (existing_bans) { existing_bans << 'Religion' }
ban_something.call(ban_religion_lambda)
puts "-- Is Religion banned? #{@bans.include?('Religion')}"
# Ban everything
puts "** Let's ban EVERYTHING"
ban_something.call(EVERYTHING)
puts "-- Is Marian banned? #{@bans.include?('Marian')}"
puts "-- Is Walking banned? #{@bans.include?('Walking')}"
puts "-- Is Cheesus banned? #{@bans.include?('Cheesus')}"
puts "** Is the function of banning the same for EVERYTHING and Religion?"
puts "-- Answer #{EVERYTHING.class == ban_religion_lambda.class}"
# Results:
#
# ** Some simple tests
# -- Is Breathing banned? false
# -- Is Walking banned? false
# ** Let's ban Religion
# -- Is Religion banned? true
# ** Let's ban EVERYTHING
# -- Is Marian banned? true
# -- Is Walking banned? true
# -- Is Cheesus banned? true
# ** Is the function of banning the same for EVERYTHING and Religion?
# -- Answer true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment