class Hoodoo::StringInquirer

Given a string, provides an object that takes the string’s value and turns it into a method “#{value}?”, returning true; other methods all respond false.

Example:

greeting = Hoodoo::StringInquirer.new( 'hello' )
greeting.hello? # => true
greeting.hi?    # => false

Private Instance Methods

method_missing( method_name, *arguments ) click to toggle source

Called when a String receives a message it cannot handle. This is where StringInquirer adds in its string-value-dependent “fake” boolean method. For any method name ending in “?”, returns true if the string value matches the name except for that “?”, else false. If the method name does not end in “?”, the call is passed to super.

method_name

Method name that wasn’t found in object instance.

*arguments

List of arguments passed to the method.

Calls superclass method
# File lib/hoodoo/utilities/string_inquirer.rb, line 46
  def method_missing( method_name, *arguments )
    if method_name[ -1 ] == '?'
      self == method_name[ 0..-2 ]
    else
      super
    end
end
respond_to_missing?( method_name, include_private = false ) click to toggle source

Asks if this object can respond to a given method. In practice returns true for any method name ending in “?”.

method_name

Method name to ask about

include_private

If true include private methods in the test, else if omitted or false, ignore them.

# File lib/hoodoo/utilities/string_inquirer.rb, line 33
def respond_to_missing?( method_name, include_private = false )
  method_name[ -1 ] == '?'
end