Created
May 8, 2014 16:33
-
-
Save iamvery/bb1d652674d432f095cc to your computer and use it in GitHub Desktop.
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
require 'contracts' | |
include Contracts | |
class ConvertableToHash | |
def self.valid?(thing) | |
thing.to_h | |
true | |
rescue TypeError | |
false | |
end | |
end | |
Contract ConvertableToHash => Any | |
def with_a_hashy_input(input) | |
input = input.to_h | |
input.delete(:abc) | |
end | |
class Thing | |
def to_h | |
{ abc: 123 } | |
end | |
end | |
puts with_a_hashy_input(Thing.new) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment