lib/peeky/predicates/attr_reader_predicate.rb
# Match will return true if the method_info seems to be an :attr_reader
#
# @param instance [Object] instance the object that has this method (required)
# @param method_info [String] method info (required)
Match will return true if the method_info seems to be an :attr_reader
Match will return true if the method_info seems to be an : attr_reader
def match(instance, method_info)
        return false unless prerequisites(instance, method_info)
        method_name = method_info.name
        new_value = SecureRandom.alphanumeric(20)
        code = <<-RUBY
          @#{method_name} = '#{new_value}' # eg. @variable = 'a3bj7a3bj7a3bj7a3bj7'
        RUBY
        cloned = instance.clone
        cloned.instance_eval(code)
        begin
          current_value = cloned.send(method_name)
        rescue StandardError 
          current_value = nil
        end
        current_value == new_value
      end
def match ( instance , method_info ) return false unless prerequisites ( instance , method_info ) method_name = method_info . name new_value = SecureRandom . alphanumeric ( 20 ) code = <<-RUBY 
          @ #{ method_name }  = ' #{ new_value } ' # eg. @variable = 'a3bj7a3bj7a3bj7a3bj7'
         RUBY cloned = instance . clone cloned . instance_eval ( code ) begin current_value = cloned . send ( method_name ) rescue StandardError current_value = nil end current_value == new_value end
Match will return true if the method_info seems to be an :attr_reader
Match will return true if the method_info seems to be an : attr_reader
# Refactor: Fragile # Really need to handle exceptions and types better # old_value = instance.send(method_name) # This code works by # 1. Set @name_of_method variable to random value # 2. Call method name and see if it returns that value # 3. Return match<true> if the values are equal #=> exception
instance
instance the object that has this method (required)
instance the object that has this method ( required )
method_info
method info (required)
method info ( required )