Sha256: 8b7b54d0b70ea5143132b5578f1aaab17a3d0d05fe7f7ac245bf44785204687b

Contents?: true

Size: 474 Bytes

Versions: 6

Compression:

Stored size: 474 Bytes

Contents

require "method_callbacks/method"

module MethodCallbacks
  class Finder
    attr_reader :name

    def initialize(name)
      @name = name
    end

    def find
      @_find ||= {}
      @_find[name] ||= methods.select { |callback| callback == self }.first
    end

    def find_or_new
      find || new
    end

    private

    def new
      method = Method.new(name)
      methods << method
      method
    end

    def methods
      @_methods ||= []
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
method_callbacks-1.2.2 lib/method_callbacks/finder.rb
method_callbacks-1.2.1 lib/method_callbacks/finder.rb
method_callbacks-1.2.0 lib/method_callbacks/finder.rb
method_callbacks-1.1.1 lib/method_callbacks/finder.rb
method_callbacks-1.1.0 lib/method_callbacks/finder.rb
method_callbacks-1.0.0 lib/method_callbacks/finder.rb