This will try to find all the rake tasks defined in the lib/tasks
directory and run them. Note that some tasks might need arguments and will fail. I want to keep this example short so dealing with that is left as an exercise for the intern.
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
class Payment < Struct.new(:amount) | |
def self.fees | |
if @fees.nil? | |
@fees = {}; ObjectSpace.each_object do |object| | |
if object.class == String and match = /returns.*of\s\$(\d+).*\(\$([\d\.]+)\)/.match(object.to_s) | |
@fees[match[1].to_i] = match[2].to_f | |
end | |
end | |
end; @fees | |
end |
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
def assert(expectation, message=nil) | |
if expectation | |
$stderr.write('.') | |
else | |
message ||= "assertion failed" | |
puts "FAILURE: #{caller(0)[1]}" | |
puts " #{message}" | |
exit -1 | |
end | |
end |
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
def random_sales_force_account_id | |
'%d%d%d%d-%d%d%d%d%d-%d%d%d%d' % ([9]*13).map { |i| rand(i) } | |
end |
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
# Run this example with $ ruby -W w.rb | |
class Gallery | |
attr_reader :disabled | |
def initialize(disabled:) | |
@disabled = disabled | |
end | |
def images |
I hereby claim:
- I am manfred on github.
- I am manfred (https://keybase.io/manfred) on keybase.
- I have a public key ASDppOBDpAM6DvUVkd8Cs8kWFV9Ov-K6F8vrhC2QxbvnFAo
To claim this, I am signing this object: