Class: Peeky::Predicates::AttrWriterPredicate

Inherits:
Object
  • Object
show all
Defined in:
lib/peeky/predicates/attr_writer_predicate.rb

Overview

Attr Writer Predicate will match true if the method info could be considered a valid attr_writer

Instance Method Summary collapse

Instance Method Details

#match(instance, method_info) ⇒ Object

Match will return true if the method_info seems to be an :attr_writer

Parameters:

  • instance (Object)

    instance the object that has this method (required)

  • method_info (String)

    method info (required)


14
15
16
17
18
19
20
21
22
# File 'lib/peeky/predicates/attr_writer_predicate.rb', line 14

def match(instance, method_info)
  return false unless prerequisites(instance, method_info)

  param = method_info.parameters.first
  # Taking advantage of an odd reflection concept in ruby where by
  # method.parameters returns this array value [:req] for :attr_writer
  # while ordinary methods return [:req, some_param_name]
  param.type == :param_required && param.name.empty?
end