Skip to content

Instantly share code, notes, and snippets.

@iamvery
Created May 8, 2014 16:33
Show Gist options
  • Save iamvery/bb1d652674d432f095cc to your computer and use it in GitHub Desktop.
Save iamvery/bb1d652674d432f095cc to your computer and use it in GitHub Desktop.
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