Skip to content

Instantly share code, notes, and snippets.

@pelle
Created December 10, 2010 20:00
Show Gist options
  • Save pelle/736718 to your computer and use it in GitHub Desktop.
Save pelle/736718 to your computer and use it in GitHub Desktop.
FUNGIBLE = [:coin, :coin, :coin, :coin]
INFUNGIBLE = [:coin, :cow, :wine, :kebab]
# Is each unit in the list of assets interchangeable?
def fungible?(assets)
if assets.all?{ |unit| assets.all? {|other_unit| unit==other_unit }}
puts "#{assets.inspect} is fungible"
else
puts "#{assets.inspect} is not fungible"
end
end
fungible?(FUNGIBLE)
# [:coin, :coin, :coin, :coin] is fungible
fungible?(INFUNGIBLE)
# [:coin, :cow, :wine, :kebab] is not fungible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment