Create one-off refinements for classes, without (most) of the boilerplate.
Put this in your Gemfile:
gem 'patched'
Or this in your terminal:
gem install patched
Basically, this:
using patched(ClassName) {
# add methods to ClassName here
}
The syntax is, unfortunately, quite important.
class LolMaths
include Patched
using patched(Fixnum) {
def to_word
case self
when 0 then "zero"
when 1 then "one"
when 2 then "two"
# ...
end
end
}
def add(*numbers)
numbers.reduce("") {|sum, num| sum + num.to_word }
end
end
Forthcoming.
Any ideas or attempts to make this less of a horrible hack would be very much appreciated.