Skip to content

Instantly share code, notes, and snippets.

def coerce(other)
unless other.is_a?(Numeric)
raise TypeError, "Can't coerce #{other}"
end
operator = caller.first.scan(/`(.*)'/).first.first.to_sym
return [Feet.new(other), self] if operator == :*
raise TypeError "Can't coerce #{other} for operator '#{operator}'"
@doesterr
doesterr / refactoring_example.rb
Created July 19, 2012 00:23 — forked from mehowte/refactoring_example.rb
Simple refactoring exercise
# This is a simple refactoring exercise.
#
# What to do?
#
# 1. Look at the code of the class CorrectAnswerBehavior
# 2. Try to see what it does by running `ruby refactoring_example.rb`
# 3. Record characterisation tests by running `ruby refactoring_example.rb --record`
# 4. Make the code beautiful;)
# 5. You are allowed to modify only the code between markers (REFACTORING START/REFACTORING END).
# 6. Test must pass! You can run them with command `ruby refactoring_example.rb --test`
@doesterr
doesterr / gist:2479990
Created April 24, 2012 14:10
adyen rspec output
rspec -c
.....................................................................................................................................................................................................................................................................#<Adyen::API::PaymentService::AuthorisationResponse:0x00000103152e18 @http_response=#<Net::HTTPInternalServerError 500 Internal Server Error readbody=true>, @xml_querier=<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>security 010 Not allowed</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
@doesterr
doesterr / application.rb
Created April 21, 2012 17:49
active support concern
# config/application.rb
config.autoload_paths += Dir["#{config.root}/app/models/**/"]