Sha256: 037ba83449da697b9d8aa0adbe1349ffb59b83408087d70ca2738dcaaae27982

Contents?: true

Size: 573 Bytes

Versions: 1

Compression:

Stored size: 573 Bytes

Contents

# frozen_string_literal: true

module Hollaback
  # A callback that can be executed later
  class Callback
    attr_reader :type, :executable

    def initialize(type, execute = nil, &block)
      @type       = type
      @executable = (execute || block)
    end

    def build
      case executable
      when Symbol
        ->(target, &block) { target.send(executable, &block) }
      when Proc
        ->(target) { target.instance_eval(&executable) }
      else
        raise ArgumentError, "Invalid callback argument: #{executable.inspect}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hollaback-0.1.1 lib/hollaback/callback.rb