Class: MethodCallbacks::Finder

Inherits:
Object
  • Object
show all
Defined in:
lib/method_callbacks/finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Finder

Returns a new instance of Finder.



7
8
9
# File 'lib/method_callbacks/finder.rb', line 7

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/method_callbacks/finder.rb', line 5

def name
  @name
end

Instance Method Details

#findObject



11
12
13
14
# File 'lib/method_callbacks/finder.rb', line 11

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

#find_or_newObject



16
17
18
# File 'lib/method_callbacks/finder.rb', line 16

def find_or_new
  find || new
end