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
import Control.Monad | |
data Tree a = EmptyTree | Node a (Tree a) (Tree a) | |
(<<) EmptyTree value = Node value EmptyTree EmptyTree | |
(<<) (Node value left right) newValue = if newValue < value | |
then Node value (left << newValue) right | |
else Node value left (right << newValue) | |
toArray EmptyTree = [] |
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
module Inject | |
class Injector | |
def self.inject(*args, &block) | |
options = args.last.kind_of?(Hash) ? args.pop : {} | |
target = options[:receiver] || block.binding.eval("self") | |
modules = args | |
modules.each { |mod| mod.before_inject(target) if mod.respond_to?(:before_inject)} | |
return_value = new(modules).inject_into(target, &block) |
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
# It's common, while creating a bunch of very similar methods, to create | |
# a loop to define them all at once. (Very simple) example follows: | |
week_days = %w[sunday monday tuesday wednesday thursday friday saturday] | |
week_days.each do |day| | |
define_method("events_on_#{day}") do | |
events.select { |event| event.day == day } | |
end | |
end |
NewerOlder