Module: Punchout::Punchable

Defined in:
lib/punchout.rb

Overview

Classes that include this module become punchable.

Calling ‘Instance#punch(obj)`, will return a class, the class of which is determined by one or more characteristics of `obj`

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#matcherObject

An instance of something that acts like a Matcher



20
21
22
# File 'lib/punchout.rb', line 20

def matcher
  @matcher
end

Instance Method Details

#punch(obj) ⇒ Class

Punches a class based on the object passed and the Matchers tied to this Punchout::Punchable

Parameters:

  • obj

    The object that determines what we punch

Returns:

  • (Class)

    The Class that matched against ‘obj`



34
35
36
# File 'lib/punchout.rb', line 34

def punch(obj)
  puncher.punch(obj)
end

#punchable?Boolean

Indicates whether this module is punchable

TODO: This method might become an indication of whether any punchers are registered. Or it just might die. Not sure yet.

Returns:

  • (Boolean)


15
16
17
# File 'lib/punchout.rb', line 15

def punchable?
  true
end

#puncherPuncher

The Punchout::Puncher assocated with this punchable.

Returns:



25
26
27
# File 'lib/punchout.rb', line 25

def puncher
  @puncher ||= Puncher.new
end