module Invokable

A module that attempts to generalize the notion of a first class function or Procs as they are often called in Ruby. It enables any class and it's objects to be treated as first-class functions. It also provides helpers includes helpers that can be used for performing higher-order operations on and object that can be treated as a function.

@example

class TwitterPoster
  include Invokable

  def initialize(model)
    @model = model
  end

  def call(user)
    # do the dirt
    ...
    TwitterStatus.new(user, data)
  end
end

TwitterPoster.call(Model.find(1)) # => #<TwitterPoster ...>
TwitterPoster.call(Model.find(1), current_user) # => #<TwitterStatus ...>

Constants

INCLUDED_MODULES
VERSION

Public Class Methods

included(base) click to toggle source
# File lib/invokable.rb, line 33
def self.included(base)
  INCLUDED_MODULES.each do |mod|
    base.include(mod)
    base.extend(mod)
  end
  base.extend(ClassMethods)
end